Java连接MySQL数据库小工具类JDBCutil(小白一个 请多指教)
package queryRunnerTest;
import java.sql.Connection;
import java.sql.DriverManager;
public class JDBCutil {
private static Connection con ;
static {
try {
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/test1";
String username="root";
String password="123456";
con=DriverManager.getConnection(url,username,password);
} catch (Exception ex) {
System.out.println(ex+"数据库连接出错");
}
}
public static Connection getConnection(){
return con;
}
}