站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题jsp数据库连接错误,大家帮我看下~

jsp数据库连接错误,大家帮我看下~

摘要: jsp数据库连接错误,大家帮我看下~


<%
int PageSize = 3;
int ShowPage = 1;
int Rowcount = 0;
int PageCount = 0;
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
public void jspInit()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:db");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery("select * from book");
rs.last();
Rowcount=rs.getRow();
PageCount=((Rowcount % PageSize) == 0 ?
(Rowcount/PageSize) : (Rowcount/PageSize)+1);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
public void jspDestroy()
{
try{
rs.close();
stmt.close();
con.close();
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
%>
提示错误:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 0 in the jsp file: /pagescount.jsp

Generated servlet error:
[javac] Compiling 1 source file

D:/Tomcat/work/Standalone/localhost/ky/pagescount_jsp.java:49: 非法的表达式开始
public void jspInit()
^



An error occurred at line: -1 in the jsp file: null

Generated servlet error:
D:/Tomcat/work/Standalone/localhost/ky/pagescount_jsp.java:77: 需要 ';'
^
2 错误




去掉以下部分
public void jspInit()
{

}


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:db");


public void JspInit()


在JSP中定义JAVA方法要使用 <%! ....%>

这个可以直接改成这样用
<%
int PageSize = 3;
int ShowPage = 1;
int Rowcount = 0;
int PageCount = 0;
Connection con=null;
Statement stmt=null;
ResultSet rs=null;

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:db");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery("select * from book");
rs.last();
Rowcount=rs.getRow();
PageCount=((Rowcount % PageSize) == 0 ?
(Rowcount/PageSize) : (Rowcount/PageSize)+1);
}catch(Exception e){
System.out.println(e.toString());
}
try{
rs.close();
stmt.close();
con.close();
}catch(Exception ex){
System.out.println(ex.toString());
}

%>


现在来说没必要去用什么odbc

用jdbc


问题还没有解决啊,请大家继续给提示帮助啊~~~~~~~~


把jspInit和jspDestory都去掉...建议不要用odbc..直接用jdbc..



在JSP中定义JAVA方法要使用 <%! ....%>,这样才能编译成servlet得成员函数!
要不你把数据库部分独立出来,写在一个javabean中!


↑返回目录
前一篇: 如何在jsp页里面实现tab页
后一篇: 如何在JSP中实现文件下载