数据库;连接代码如下,是 ACESS的
package conn;
import java.sql.*;
public class connDb{
public static String prox="sun.jdbc.odbc.JdbcOdbcDriver";
public static Connection con;
public static String pname="jdbc:odbc:book";
public connDb(){
}
public static Connection getConnection(){
try{
Class.forName(prox);
con=DriverManager.getConnection(pname);
}catch(ClassNotFoundException e){
System.out.println(e.getMessage());
}catch(SQLException e){
System.out.println(e.getMessage());
}
if(con==null){
System.out.println("没有获得数据库连接");
}
return con;
}
public static ResultSet executeQuery(String sql){//查询
con=connDb.getConnection();
ResultSet rs=null;
try{
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException e){}
return rs;
}
public static boolean uptate(String sql){//删除,更新
boolean b=false;
Connection con=null;
PreparedStatement ps=null;
try{
con=connDb.getConnection();
ps=con.prepareStatement(sql);
if(ps.executeUpdate()>0){
b=true;
}else{
b=false;
}
}catch(SQLException e){
b=false;
e.printStackTrace();
}finally{
System.out.println(ps+"DataBase.delete()"+sql);
try{
if(ps!=null){
ps.close();
}
}catch(SQLException e){
ps=null;
}
try{
if(con!=null){
con.close();
}
}catch(SQLException e){
con=null;
}
}
return b;
}
}
jsp文件如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<%@ page import="conn.connDb"%>
<jsp:useBean id="con" class="conn.connDb" scope="session"/>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
%>
<%
String sql="select * from main order by id desc";
ResultSet rs=con.executeQuery(sql);
try{
while(rs.next()){%>
<%=rs.getString("content")%>
<%
}
}catch(SQLException e){out.println("错误");}
%>
<body>
</body>
</html>
出现的异常如下:
org.apache.jasper.JasperException: An exception occurred processing JSP page /web/index.jsp at line 18
15: <%
16: String sql="select * from main order by id desc";
17:
18: ResultSet rs=con.executeQuery(sql);
19: try{
20: while(rs.next()){%>
21: <%=rs.getString("content")%>
不知道怎么弄,一天了,还不行,请帮忙看下,要怎么解决,谢了