String sql="select * from t_dept where id = ? and name = ?"; PreparedStatement ps=conn.prepareStatement(sql); ps.setInt(1,id); ps.setString(2,name); System.out.println(ps); ResultSet resultSet = ps.executeQuery(); while(resultSet.next()){ flag++; // //对应的类是自己数据对应的 User user = new User(); user.setId(resultSet.getInt(1)); user.setName(resultSet.getString(2)); System.out.println(user);
ps直接执行ps.executeQuery()不要在括号里写东西
错误示范:ps.executeQuery(sql)
错误示范:ps.executeQuery(sql)
错误示范:ps.executeQuery(sql)