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;

汪汪一只猫
浏览 1373回答 3
3回答

一只名叫tom的猫

是别的文件有问题  这个项目的jar包和写法不是正常的jdbc 

慕森卡

Statement stmt = null; 你的Statement 没有初始化啊

绝地无双

Connection conn=DriverManager.getConnection(); 。。。。 。。。。 stateMent state=conn.createStateMent(); ....... .......
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java