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);

posted on 2012-09-16 20:48  J2ee攻城狮  阅读(231)  评论(0)    收藏  举报

导航