JAVA 连接 MySQL
1.JAVA连接MySQL
(1)
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/officedb?useUnicode=true&characterEncoding=gb2312";
String user = "root";
String password="xing123";
System.setProperty("jdbc.drivers",driver);
Connection conn=DriverManager.getConnection(url, user, password);
(2)
Class.forName("com.mysql.jdbc.Driver");
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost/qq"+"?useUnicode=true&characterEncoding=gbk","root","xing123");
String sql="select * from tbluser where userno=? and userpsw=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1, userno);pstmt.setString(2, userpsw);
浙公网安备 33010602011771号