Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说java mysql executequery_jdbc连接数据库 Statement的executeQuery方法报空指针异常?[通俗易懂],希望能够帮助你!!!。
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String membertype = "";//登录用户类型
try {
StringBuffer sb = new StringBuffer();
sb.append(" select membertype from m_b_broker where brokerid='"+logonUser+"' ");
System.out.print(sb);
rs = stmt.executeQuery(sb.toString()); //这里报出空指针异常
System.out.print("1111");
while (rs.next()) {
membertype=rs.getString("membertype");
}
rs.close();
rs = null;
stmt.close();
stmt = null;
conn.close();
conn = null;
}
catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return membertype;