日期:2014-05-17 浏览次数:20831 次
public String login(){ String sql = "select * from user where name=? and password= ? "; System.out.println(name+":"+pass); try { rs = db.executeQuery(sql, new String[]{name,pass}); } catch (Exception e) { e.printStackTrace(); new java.sql.SQLException(); } if(rs==null){ db.close(); return "not"; }else{ db.close(); return SUCCESS; } }
public ResultSet executeQuery (String sql,String[] value) throws Exception{ try { // 捕捉异常 if(conn==null){ conn = getConnection(); // 调用getConnection()方法构造Connection对象的一个实例conn }else{ } System.out.println(value.length); stmt = conn.prepareStatement(sql); for(int i=1;i<=value.length;i++){ stmt.setString(i, value[i-1]); } rs = stmt.executeQuery(sql);//4.执行查询 } catch (SQLException ex) { System.err.println(ex.getMessage()+"aaaaa"); // 输出异常信息 } return rs; }
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 password= ?' at line 1