当前位置: 技术问答>java相关
这个错误困扰了我两天了,我还不敢确认是不是服务器的错误,痛苦~~~~~~~~~~~
来源: 互联网 发布时间:2015-06-29
本文导语: 我写了一个应用Bean的JSP程序,包括DbConnection.java、ViewQueryBean.java和 ViewQuery.jsp,其中头两个文件存放在目录webapps/examples/web-inf/classes/aboutjspdb下(已经编译过了),后面一个存放在目录webapps/examples/jsp/database DbConnection.java...
我写了一个应用Bean的JSP程序,包括DbConnection.java、ViewQueryBean.java和
ViewQuery.jsp,其中头两个文件存放在目录webapps/examples/web-inf/classes/aboutjspdb下(已经编译过了),后面一个存放在目录webapps/examples/jsp/database
DbConnection.java如下所示:
package aboutjspdb;
import java.util.*;
import java.sql.*;
import java.io.*;
public class DbConnection
{
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
public DbConnection()
{
}
public boolean openConnection()
{
String url=new String("jdbc:odbc:Instore Army");
String user="sa";
String password="";
try
{
Class.forName("sun.jdbc:odbc:JdbcOdbcDriver");
}catch(ClassNotFoundException e){
System.out.println("JDBC登录过程中出现错误:"+e.getMessage());
return false;
}
try{
this.conn=DriverManager.getConnection(url,user,password);
}catch(SQLException e){
System.out.println("生成Connection过程中出现错误:"+e.getMessage());
return false;
}
return true;
}
public ResultSet executeQuery(String query) throws SQLException
{
this.stmt = conn.createStatement();
this.rset = stmt.executeQuery(query);
return rset;
}
public void executeUpdate(String query) throws SQLException
{
this.stmt = conn.createStatement();
stmt.executeUpdate(query);
if(stmt!=null) stmt.close();
}
public void close() throws SQLException
{
if(conn!=null) conn.close();
if(rset!=null) rset.close();
if(stmt!=null) stmt.close();
}
protected void finalize() throws Throwable
{
this.close();
}
}
ViewqueryBean如下所示:
package aboutjspdb;
import java.sql.*;
public class ViewQueryBean
{
aboutjspdb.DbConnection dc = null;
ResultSet rset = null;
public ViewQueryBean()
{
dc = new aboutjspdb.DbConnection();
}
public boolean openConnection()
{
return dc.openConnection();
}
public void executeQuery(String query) throws SQLException
{
this.rset = dc.executeQuery(query);
}
public void executeUpdate(String query) throws SQLException
{
dc.executeUpdate(query);
}
public int getColumnCount() throws SQLException
{
ResultSetMetaData rsmd = rset.getMetaData();
return rsmd.getColumnCount();
}
public String getColumnName(int index) throws SQLException
{
ResultSetMetaData rsmd=rset.getMetaData();
return rsmd.getColumnName(index);
}
public String getData(int index) throws SQLException
{
return rset.getString(index).trim();
}
public String getData(String columnName) throws SQLException
{
return rset.getString(columnName).trim();
}
public boolean next() throws SQLException
{
return rset.next();
}
public void close() throws SQLException
{
if(rset!=null) rset.close();
if(dc!=null) dc.close();
}
protected void finalize() throws Throwable
{
close();
}
}
ViewQuery.jsp如下所示:
SQL 查询语句
结果 VIEW
当我在IE的url中打入:http://localhost:8080/examples/jsp/database/ViewQuery.jsp时出现如下错误:
Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error
--------------------------------------------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at aboutjspdb.DbConnection.executeQuery(DbConnection.java:106)
at aboutjspdb.ViewQueryBean.executeQuery(ViewQueryBean.java:31)
at org.apache.jsp.ViewQuery$jsp._jspService(ViewQuery$jsp.java:98)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Unknown Source)
请问是什么意思,应该如何解决?谢谢!!!!!
ViewQuery.jsp,其中头两个文件存放在目录webapps/examples/web-inf/classes/aboutjspdb下(已经编译过了),后面一个存放在目录webapps/examples/jsp/database
DbConnection.java如下所示:
package aboutjspdb;
import java.util.*;
import java.sql.*;
import java.io.*;
public class DbConnection
{
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
public DbConnection()
{
}
public boolean openConnection()
{
String url=new String("jdbc:odbc:Instore Army");
String user="sa";
String password="";
try
{
Class.forName("sun.jdbc:odbc:JdbcOdbcDriver");
}catch(ClassNotFoundException e){
System.out.println("JDBC登录过程中出现错误:"+e.getMessage());
return false;
}
try{
this.conn=DriverManager.getConnection(url,user,password);
}catch(SQLException e){
System.out.println("生成Connection过程中出现错误:"+e.getMessage());
return false;
}
return true;
}
public ResultSet executeQuery(String query) throws SQLException
{
this.stmt = conn.createStatement();
this.rset = stmt.executeQuery(query);
return rset;
}
public void executeUpdate(String query) throws SQLException
{
this.stmt = conn.createStatement();
stmt.executeUpdate(query);
if(stmt!=null) stmt.close();
}
public void close() throws SQLException
{
if(conn!=null) conn.close();
if(rset!=null) rset.close();
if(stmt!=null) stmt.close();
}
protected void finalize() throws Throwable
{
this.close();
}
}
ViewqueryBean如下所示:
package aboutjspdb;
import java.sql.*;
public class ViewQueryBean
{
aboutjspdb.DbConnection dc = null;
ResultSet rset = null;
public ViewQueryBean()
{
dc = new aboutjspdb.DbConnection();
}
public boolean openConnection()
{
return dc.openConnection();
}
public void executeQuery(String query) throws SQLException
{
this.rset = dc.executeQuery(query);
}
public void executeUpdate(String query) throws SQLException
{
dc.executeUpdate(query);
}
public int getColumnCount() throws SQLException
{
ResultSetMetaData rsmd = rset.getMetaData();
return rsmd.getColumnCount();
}
public String getColumnName(int index) throws SQLException
{
ResultSetMetaData rsmd=rset.getMetaData();
return rsmd.getColumnName(index);
}
public String getData(int index) throws SQLException
{
return rset.getString(index).trim();
}
public String getData(String columnName) throws SQLException
{
return rset.getString(columnName).trim();
}
public boolean next() throws SQLException
{
return rset.next();
}
public void close() throws SQLException
{
if(rset!=null) rset.close();
if(dc!=null) dc.close();
}
protected void finalize() throws Throwable
{
close();
}
}
ViewQuery.jsp如下所示:
SQL 查询语句
结果 VIEW
当我在IE的url中打入:http://localhost:8080/examples/jsp/database/ViewQuery.jsp时出现如下错误:
Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error
--------------------------------------------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at aboutjspdb.DbConnection.executeQuery(DbConnection.java:106)
at aboutjspdb.ViewQueryBean.executeQuery(ViewQueryBean.java:31)
at org.apache.jsp.ViewQuery$jsp._jspService(ViewQuery$jsp.java:98)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Unknown Source)
请问是什么意思,应该如何解决?谢谢!!!!!
|
好象回答过哟?