简单的连接语句:
try{ Class.forName("org.gjt.mm.mysql.Driver"); Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","zqy01"); /* 注:test为数据库名称,root为用户名,zqy01为密码 */ Statement stmt=conn.createStatement(); String sql="select * from users where username='"+username+"'"; sql+="and password='"+password+"'"; ResultSet rs=stmt.executeQuery(sql); if(rs.next()){ ........./*这部分省略了*/ }
阅读(980) | 评论(0) | 转发(0) |