我是用连接池链接数据库SQLServer2000,但在Bean里执行到DataSource对象的
getConnection()方法是总是发生空指针异常,代码如下
Connection con = null;
Statement stmt = null ;
ResultSet rs = null ;
DataSource ds = null;
public boolean selectUserData ( String key_username , String key_password )throws SQLException {
boolean bool = false;
try{
con = ds.getConnection();
//程序运行到这里就停住了,报错是java.lang.NullPointerException.是什么原因呢?
stmt = con.createStatement();
StringBuffer sql = new StringBuffer () ;
sql.append ( "select userName,passWord \n" ) ;
sql.append ( " from key_user" ) ;
rs = stmt.executeQuery ( sql.toString () ) ;
bool = false;
while ( rs.next () ) {
if(key_username == rs.getString(1) && key_password == rs.getString(2))
bool = true;
break;
}
rs.close () ;
stmt.close () ;
}catch (SQLException e) {
e.printStackTrace();
}
return bool ;
}
偶是菜鸟,请各位大虾们指点...
------解决方案--------------------
DataSource ds = null;
是这个没有初始值