Jdbc Java.lang.NullPointerException

时间:2018-04-18 18:35:30

标签: java mysql jsp jdbc

下面是我的jsp页面的代码部分,当我打印时,rs.getString(1)打印完美但是只要我把rs.getString(1)放在if块中就会显示空指针异常。请帮忙

String nam=request.getParameter("n");
String query = "select name from ques where username='"+userid+"'";

Statement st=con.prepareStatement(query);

ResultSet rs = st.executeQuery(query);


while(rs.next()){

    out.println(rs.getString(1));

    if(rs.getString(1).equals(nam)){

        out.print("hello");

    }

}

0 个答案:

没有答案