当前位置: 技术问答>java相关
数据库连接的问题,不要认为简单!
来源: 互联网 发布时间:2015-11-16
本文导语: 我连接access数据库,总是有个问题: 我用的程序是在网上下载的,如下: JSP数据库操作例程 - 数据分页显示 - JDBC 2.0 - Access 姓名 年龄 0){ //将记录指针定位到待显示页的第一条记录...
我连接access数据库,总是有个问题:
我用的程序是在网上下载的,如下:
JSP数据库操作例程 - 数据分页显示 - JDBC 2.0 - Access
姓名
年龄
0){
//将记录指针定位到待显示页的第一条记录上
sqlRst.absolute((intPage-1) * intPageSize + 1);
//显示数据
i = 0;
while(i
第页 共页 下一页 1){%>上一页
我的数据库是在管理工具中建的用户SDN,为了保险,我还建了系统SDN,名称都是ChuanZhen
我是用tomcat做的服务器,在浏览器中直接键入的调用jsp网页,我是想问一声,是不是还要
添加别的javabean什么的,或是别的类.
我用的是tomcat4.0,jdk1.3.1
出错总是--------------------------------------------------------------------------------
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
org.apache.jasper.JasperException: Unable to compile class for JSP
C:tomcatworklocalhost_ChuanZhenkkk$jsp.java:248: Incompatible type for method. Explicit cast needed to convert java.lang.Throwable to java.lang.Exception.
if (pageContext != null) pageContext.handlePageException(t);
^
1 error
at org.apache.jasper.compiler.Compiler.compile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
at java.lang.Thread.run(Thread.java:484)
请大侠指教,如要添加java类,请贴上!
--------------------------------------------------------------------------------
我用的程序是在网上下载的,如下:
JSP数据库操作例程 - 数据分页显示 - JDBC 2.0 - Access
姓名
年龄
0){
//将记录指针定位到待显示页的第一条记录上
sqlRst.absolute((intPage-1) * intPageSize + 1);
//显示数据
i = 0;
while(i
第页 共页 下一页 1){%>上一页
我的数据库是在管理工具中建的用户SDN,为了保险,我还建了系统SDN,名称都是ChuanZhen
我是用tomcat做的服务器,在浏览器中直接键入的调用jsp网页,我是想问一声,是不是还要
添加别的javabean什么的,或是别的类.
我用的是tomcat4.0,jdk1.3.1
出错总是--------------------------------------------------------------------------------
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
org.apache.jasper.JasperException: Unable to compile class for JSP
C:tomcatworklocalhost_ChuanZhenkkk$jsp.java:248: Incompatible type for method. Explicit cast needed to convert java.lang.Throwable to java.lang.Exception.
if (pageContext != null) pageContext.handlePageException(t);
^
1 error
at org.apache.jasper.compiler.Compiler.compile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
at java.lang.Thread.run(Thread.java:484)
请大侠指教,如要添加java类,请贴上!
--------------------------------------------------------------------------------
|
检查你取出的两个字段是否都是String型
while(sqlRst.next())
while(sqlRst.next())
|
//获取记录总数
sqlRst.last();
intRowCount = sqlRst.getRow();
改为:
strSQL = "select count(*) as totalcount from MA_YH";
sqlRst = sqlStmt.executeQuery(strSQL);
intRowCount = sqlRst.getInt("totalcount");
sqlRst.close();
sqlRst.last();
intRowCount = sqlRst.getRow();
改为:
strSQL = "select count(*) as totalcount from MA_YH";
sqlRst = sqlStmt.executeQuery(strSQL);
intRowCount = sqlRst.getInt("totalcount");
sqlRst.close();