H
Haha...
Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是resin, mssql 2000 person版,写了个bean如下:
bean编译通过,但是页面错误,信息如下:
大虾帮忙!!!
java.lang.NullPointerException
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at hamduke.dbbean.DBBean.getConn(DBBean.java:37)
at hamduke.dbbean.DBBean.executeQuery(DBBean.java:48)
at _index__jsp._jspService(/index.jsp:141)
at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:181)
at com.caucho.server.http.Invocation.service(Invocation.java:291)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:132)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:217)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:159)
at com.caucho.server.TcpConnection.run(TcpConnection.java:136)
at java.lang.Thread.run(Thread.java:484
-----------------------------------------------------------------------------
package hamduke.dbbean;
import java.sql.*;
import java.io.*;
public class DBBean implements Serializable{
private String DBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String DBLocation = "jdbc:microsoft:sqlserver://localhost:1433";
private String LogName = "hamduke";
private String Password= "2682226";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
String strHint = "";
public void DBBean() { }
public void setDBDriver(String driver){ DBDriver = driver;}
public String getDBDriver(){ return DBDriver;
}
public void setDBLocation(String location){ DBLocation = location;}
public String getDBLocation(){ return DBLocation;
}
public void setLogName(String logname){ LogName = logname;}
public void setPassword(String password){ Password = password;}
public String getHint(){return strHint;}
public void initBean(){
try { Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("initBean(): " + e.getMessage());
}
}
public Connection getConn(){
try { conn = DriverManager.getConnection(DBLocation,LogName,Password);
}
catch(SQLException ex) {
System.err.println("getConn(): " + ex.getMessage());
}
return conn;
}//~getConn
public ResultSet executeQuery(String sql){
rs = null;
try{
conn = getConn();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
strHint = "executeQuery: " + ex.getMessage();
System.err.println(strHint);
}
return rs;
}
//execute a SQL statement without returning recordset
public boolean executeUpdate(String sql)
{
try
{
conn = getConn();
stmt = conn.createStatement();
stmt.executeUpdate(sql);
return true;
}
catch(SQLException ex)
{
strHint = "executeUpdate: " + ex.getMessage();
System.err.println(strHint);
return false;
}
}
//Close connections
public boolean closeConn()
{
try
{
if (rs!=null)
rs.close();
if (stmt!=null)
stmt.close();
if (conn!=null)
conn.close();
return true;
}
catch(SQLException ex)
{
strHint = "closeConn: " + ex.getMessage();
System.err.println(strHint);
return false;
}
}
}//~class
bean编译通过,但是页面错误,信息如下:
大虾帮忙!!!
java.lang.NullPointerException
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at hamduke.dbbean.DBBean.getConn(DBBean.java:37)
at hamduke.dbbean.DBBean.executeQuery(DBBean.java:48)
at _index__jsp._jspService(/index.jsp:141)
at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:181)
at com.caucho.server.http.Invocation.service(Invocation.java:291)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:132)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:217)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:159)
at com.caucho.server.TcpConnection.run(TcpConnection.java:136)
at java.lang.Thread.run(Thread.java:484
-----------------------------------------------------------------------------
package hamduke.dbbean;
import java.sql.*;
import java.io.*;
public class DBBean implements Serializable{
private String DBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String DBLocation = "jdbc:microsoft:sqlserver://localhost:1433";
private String LogName = "hamduke";
private String Password= "2682226";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
String strHint = "";
public void DBBean() { }
public void setDBDriver(String driver){ DBDriver = driver;}
public String getDBDriver(){ return DBDriver;
}
public void setDBLocation(String location){ DBLocation = location;}
public String getDBLocation(){ return DBLocation;
}
public void setLogName(String logname){ LogName = logname;}
public void setPassword(String password){ Password = password;}
public String getHint(){return strHint;}
public void initBean(){
try { Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("initBean(): " + e.getMessage());
}
}
public Connection getConn(){
try { conn = DriverManager.getConnection(DBLocation,LogName,Password);
}
catch(SQLException ex) {
System.err.println("getConn(): " + ex.getMessage());
}
return conn;
}//~getConn
public ResultSet executeQuery(String sql){
rs = null;
try{
conn = getConn();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
strHint = "executeQuery: " + ex.getMessage();
System.err.println(strHint);
}
return rs;
}
//execute a SQL statement without returning recordset
public boolean executeUpdate(String sql)
{
try
{
conn = getConn();
stmt = conn.createStatement();
stmt.executeUpdate(sql);
return true;
}
catch(SQLException ex)
{
strHint = "executeUpdate: " + ex.getMessage();
System.err.println(strHint);
return false;
}
}
//Close connections
public boolean closeConn()
{
try
{
if (rs!=null)
rs.close();
if (stmt!=null)
stmt.close();
if (conn!=null)
conn.close();
return true;
}
catch(SQLException ex)
{
strHint = "closeConn: " + ex.getMessage();
System.err.println(strHint);
return false;
}
}
}//~class