在javaEE中連接mysql數據庫:
Mysql:
String Driver="com.mysql.jdbc.Driver"; //驅動程序
String URL="jdbc:mysql://localhost:3306/db_name"; //連接的URL,db_name數據庫名
String Username="username"; //用戶名
String Password="password"; //密碼
Class.forName(Driver).new Instance();
Connection con=DriverManager.getConnection(URL,Username,Password);
例如:
Class.forName(com.mysql.jdbc.Driver);
Connection con=DriverManager.getConnection ("jdbc:mysql://localhost:3306/bookstore","root","root");//bookstore爲數據庫名, root root爲用戶名和密碼