当前位置: 代码迷 >> Java Web开发 >> JavaBean连接mysql总是出HTTP-500异常
  详细解决方案

JavaBean连接mysql总是出HTTP-500异常

热度:82   发布时间:2016-04-17 16:00:38.0
JavaBean连接mysql总是出HTTP-500错误
各位帮忙看看啊,我有几个这种程序都是这一种错误,郁闷几天啦!!!

jsp程序如下:
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<jsp:useBean   id= "DBconn1 "   scope= "page "   class= "NewsVersion.MySQLconn "/>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<%
String   String_SQL= "select   *   from   book ";
ResultSet   rs=DBconn1.executeQuery(String_SQL);
String   usercontent;
if(rs.next())
{
usercontent=rs.getString( "about ");
}
out.print(usercontent);
%>
</body>
</html>

Bean程序如下:

package   NewsVersion;
import   java.sql.*;
public   class   MySQLconn   {
String   DBDriver   =   "org.gjt.mm.mysql.Driver ";
String   ConnStr   =   "jdbc:mysql://localhost:3306/bookstore?user=root&password=200000&useUnicode=true&characterEncoding=8859_1 ";
Connection   conn   =   null;
ResultSet   rs   =   null;
public   MySQLconn(){
try{
Class.forName(DBDriver);
//加载数据库驱动程序
          }
catch(java.lang.ClassNotFoundException   e)   {
System.err.println( "MySQLconn():   "+e.getMessage());
                                                                                    }
                                }
public   ResultSet   executeQuery(String   sql){
//以记录集为返回值的函数
rs   =   null;
try   {
conn   =   DriverManager.getConnection(ConnStr);
//与DBMS建立链接
Statement   stmt   =   conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs   =   stmt.executeQuery(sql);
}
catch(SQLException   ex)   {
System.err.println( "aq.executeQuery: "+ex.getMessage());
}
return   rs;
}
}

错误提示:

HTTP   Status   500   -  

--------------------------------------------

type   Exception   report

message  

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

exception  

org.apache.jasper.JasperException:   /dbBean4/1.jsp(3,0)   The   value   for   the   useBean   class   attribute   NewsVersion.MySQLconn   is   invalid.   org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  相关解决方案