将myeclipse和mysql连接起来的关键语句

时间:2022-05-27 04:20:37
 1       String driverName="com.mysql.jdbc.Driver";
 2       String userName="root";
 3       String userPwd="123456";
 4       String dbName="students";
 5       String url1="jdbc:mysql://localhost:3306/"+dbName;
 6       String url2="?user="+userName+"&password="+userPwd;
 7       String url3="&useUnicode=true&characterEncoding=UTF-8";
 8       String url=url1+url2+url3;
 9       Class.forName(driverName);
10       Connection conn=DriverManager.getConnection(url);