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.
精彩评论