开发者

How to connect to a MySQL database in java? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

i have a Mysql database named "patterns" created in netbeans and i want know how to connect a database in java .


From a comment further down

public MyDBConnection() { } 
public void init(){ 
  try{ 
    Class.forName("com.mysql.jdbc.driver"); 
    myConnection=DriverManager.getConnection( "jdbc:mysql://localhost/patterns","root", "foufa" );
  } catch(Exception e开发者_如何转开发){ 
    System.out.println("Failed to get connection"); 
    e.printStackTrace(); 
  } 
} 

i tried this but it prints out "Failed to get connection"


Take a look at the JDBC trail of the Java tutorial.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜