java.sql.SQLException:CannotissueSELECTviaexecuteUpdate().

private Connection conn;

private Statement s;

private ResultSet rs;

private PreparedStatement ps;

private void closed()
{
try {

if(rs !=null) rs.close();

if(s !=null) s.close();

if(ps !=null) ps.close();

if(conn !=null) conn.close();

} catch (Exception e) {
e.printStackTrace();
}
}

public int Login(UserBean bean){
int i =0;

try {

DButil db = new DButil();
conn = db.getConn();
System.out.println(conn);
s =conn.createStatement();
String sql = "select * from user where username='"+bean.getUsername()+"'and password='"+bean.getPassword()+"'";
System.out.println(sql);
//i = s.executeUpdate(sql);
i=s.executeUpdate(sql);

} catch (Exception e) {
e.printStackTrace();
}finally{

this.closed();

}

return i;
最新回答
鹿人甲驴人乙

2024-04-25 00:25:37

错误信息是说 你原本是select 的语句写成update了

你那个sql 语句 是select 不能用
s.executeUpdate(sql);
要用
s.executeQuery(sql)