Go directly to the code!
[Java]
Package com. insigma. zd. group4.liuchao. jdbc;
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. SQLException;
Import java. SQL. Statement;
Public class TestJDBC {
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
// Define the mysql database Driver Class
String driver = "com. mysql. jdbc. Driver ";
// Connection string
String url = "jdbc: mysql: // localhost: 3306/test ";
// User Name
String username = "root ";
// Password
String password = "1234 ";
Try {
// Load the database driver
Class. forName (driver );
// Obtain the connection www.2cto.com
Connection conn = DriverManager. getConnection (url, username, password );
System. out. println (conn );
} Catch (ClassNotFoundException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
} Catch (SQLException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
}
}