房天下 > 房天下问答 > 业主生活 > 其他
  • 数据库mysql的查询语句预处理

    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

    提问者:gooorvdru

    发布于2010-11-30

共1个回答
  • 经典情人♂ 丨Lv 2
    检查一下你的问号是否是全角字符,因为从提示中看你两个问号不一样,一个全角,一个半角 (??)
    +1 2010-12-01 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。