首页 新闻 会员 周边

jdbc连接数据库 Statement的executeQuery方法报空指针异常?

0
悬赏园豆:10 [已解决问题] 解决于 2014-05-15 09:47

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;

指间砂的主页 指间砂 | 初学一级 | 园豆:97
提问于:2014-05-15 09:31
< >
分享
最佳答案
0

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

指间砂 | 初学一级 |园豆:97 | 2014-05-15 09:46
其他回答(2)
0

Statement stmt = null;

你的Statement 没有初始化啊

收获园豆:10
刘宏玺 | 园豆:14020 (专家六级) | 2014-05-15 09:36
0

Connection conn=DriverManager.getConnection();

。。。。

。。。。

stateMent state=conn.createStateMent();

.......

.......

Revolution_lxx | 园豆:7 (初学一级) | 2014-05-15 09:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册