publicintdenglu(Stringname,Stringpassword)throwsClassNotFoundException,SQLException{intflag=0;try{java.sql.DriverManager.registerDriver(newcom.mysql.jdbc.Driver());}catch...
public int denglu(String name,String password) throws ClassNotFoundException,
SQLException {
int flag=0;
try{
java.sql.DriverManager.registerDriver(new com.mysql.jdbc.Driver());
}
catch(SQLException ex)
{
System.err.println("连接失败");
System.exit(1);
}
String URL = "jdbc:mysql://localhost:3306/denglu";
try{
Connection con = java.sql.DriverManager.getConnection(URL,"root","891123");
String sql = "select ID from login where ID=? and mima=?";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1,name);
stmt.setString(2,password);
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
{ //该用户合法
flag=1;
}
rs.close();
stmt.close();
con.close();
}
catch(SQLException e){System.out.print(e);}
return flag;
}
不知道为什么会出现:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? and mima=?' at line 10
我认为这儿没有错误的
展开