找到了,又出现另一个错误阿,唉,太烦了阿 我看不出哪里不对 但是执行出错误 HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.
奇怪 好像就是SQLException 的了吧
这里应该有用户名和密码;还有可能没有import java.sql.*;
现在编译能通过了。但是在调用这个类的jsp页面,出现连结数据库出现错误。
bean 代码如下
package cscec.database;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import cscec.database.DBConnectionManager;public class sysdbcon {
private Connection conn = null;
private Statement stmt = null;
private PreparedStatement prepstmt = null; void init(){
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:db";
Connection conn=null; try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.out.println("personBean():"+e.getMessage());
} try{
conn=DriverManager.getConnection(sConnStr);
}
catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());
}
}
/**
* 构造数据库的连接和访问类
*/
public sysdbcon() throws Exception {
init();
//stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
} public sysdbcon(int resultSetType, int resultSetConcurrency)
throws Exception {
init();
stmt = conn.createStatement(resultSetType, resultSetConcurrency);
} /**
* 构造数据库的连接和访问类
* 预编译SQL语句
* @param sql SQL语句
*/
public sysdbcon(String sql) throws Exception {
init();
this.prepareStatement(sql);
} public sysdbcon(String sql, int resultSetType, int resultSetConcurrency)
throws Exception {
init();
this.prepareStatement(sql, resultSetType, resultSetConcurrency);
} /**
* 返回连接
* @return Connection 连接
*/
public Connection getConnection() {
return conn;
} /**
* PreparedStatement
* @return sql 预设SQL语句
*/
public void prepareStatement(String sql) throws SQLException {
prepstmt = conn.prepareStatement(sql);
} public void prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException {
prepstmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency);
} /**
* 设置对应值
*
* @param index 参数索引
* @param value 对应值
*/
public void setString(int index,String value) throws SQLException {
prepstmt.setString(index, value);
}
public void setInt(int index,int value) throws SQLException {
prepstmt.setInt(index,value);
}
public void setBoolean(int index,boolean value) throws SQLException {
prepstmt.setBoolean(index,value);
}
public void setDate(int index,Date value) throws SQLException {
prepstmt.setDate(index,value);
}
public void setLong(int index,long value) throws SQLException {
prepstmt.setLong(index,value);
}
public void setFloat(int index,float value) throws SQLException {
prepstmt.setFloat(index,value);
}
public void setBytes(int index,byte[] value) throws SQLException{
prepstmt.setBytes(index,value);
}
public void clearParameters()
throws SQLException
{
prepstmt.clearParameters();
prepstmt=null;
}
/**
* 返回预设状态
*/
public PreparedStatement getPreparedStatement() {
return prepstmt;
}
/**
* 返回状态
* @return Statement 状态
*/
public Statement getStatement() {
return stmt;
}
/**
* 执行SQL语句返回字段集
* @param sql SQL语句
* @return ResultSet 字段集
*/
public ResultSet executeQuery(String sql) throws SQLException{
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
if (stmt != null) {
return stmt.executeQuery(sql);
}else{
return null;
}
} public ResultSet executeQuery() throws SQLException {
if (prepstmt != null) {
return prepstmt.executeQuery();
}
else return null;
}
}调用的jsp如下
<code>
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ include file="../cominc.jsp"%>
<%@ page import="java.sql.*"%>
<%@ page import="cscec.database.*"%>
<%@ page errorPage="../error/error.jsp"%>
<jsp:useBean id="DB" scope="page" class="cscec.database.sysdbcon" />
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<%
int i_count = 0;
%>
<body leftmargin="0" topmargin="0">
<br>
<table width="541" border="0" align="center">
<tr>
<td> </td>
</tr>
</table>
<table width="541" height="60" border="0" align="center" cellspacing="1" bordercolorlight="ffffff" bordercolordark="000000" bgcolor="#000000">
<tr >
<td width="94" height="30" bgcolor="#666666"><div align="center"><b><font color="#ffffff" size="2">角色编号</font></b></div></td>
<td width="114" height="30" bgcolor="#666666"><div align="center"><b><font color="#ffffff" size="2">角色名称</font></b></div></td>
<td width="230" height="30" bgcolor="#666666"><div align="center"><b><font color="#ffffff" size="2">角色说明</font></b></div></td>
<td width="39" height="30" bgcolor="#666666"><div align="center"></div></td>
<td width="48" height="30" bgcolor="#666666"><div align="center"></div></td>
</tr>
<%
String fucsql="select * from QX_role order by role_id";
ResultSet RS=DB.executeQuery(fucsql);
while(RS.next()){
i_count++;
%>
<tr bgcolor="#CCCCCC">
<td height="30"><%=RS.getString("role_id")%></td>
<td height="30"> </td>
<td height="30"> </td>
<td height="30"> </td>
<td height="30"> </td>
</tr>
<%
}
RS.close();
%>
</table>
</body>
</html>
<%try{DB.close();}catch(Exception e){}%>
</code>
执行jsp显示错误页面
我看不出哪里不对
但是执行出错误
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.
String sConnStr="jdbc:odbc:db";
Connection conn;
try{
Class.forName(sDBDriver);
conn=DriverManager.getConnection(sConnStr);
}catch(java.lang.ClassNotFoundException e){
System.out.println("personBean():"+e.getMessage());
}catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());
}catch(Exception ex) {
System.out.println(ex.toString());
}
}