日期:2014-05-16 浏览次数:20837 次
try { Class.forName("com.mysql.jdbc.Driver"); System.out.println("数据库驱动程序注册成功!"); String url = "jdbc:mysql://localhost:3306/mydb"; String user = "root"; String password = "****"; Connection conn = DriverManager.getConnection(url, user, password); System.out.println("数据库连接成功"); String sql = "select password from Manager where name=?"; //准备从数据库选择密码 PreparedStatement prepare = conn.prepareCall(sql);//设定数据库查寻条件 prepare.clearParameters(); prepare.setString(1,name);//设定参数 ResultSet r = prepare.executeQuery();//执行数据库查寻 if(r.next()){//以下比较输入的号码于密码是否相同 String pass = r.getString("password").trim(); if(passWord.regionMatches(0,pass,0,pass.length())){ System.out.println("登录成功!"); ts.setVisible(false); new Manage(); } //否者告诉客户失败 else System.out.println("登录失败!"); r.close();} else{ System.out.println("false"); r.close(); conn.close(); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }