日期:2014-05-18  浏览次数:20810 次

菜鸟提问:关于TOMCAT连接MYSQL的问题!!!
我写了一个简短的程序:
<%@   page   contentType= "text/html;charset=gb2312 "%>  
<%@   page   import= "java.sql.* "%>  
<html>  
<body>  
<%Class.forName( "com.jdbc.mysql.Driver ").newInstance();  
String   url   = "jdbc:mysql://localhost/first?user=test&password=123456&useUnicode=true&characterEncoding=8859_1 ";  
//first为你的数据库名  
Connection   conn=   DriverManager.getConnection(url);  
Statement   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  
String   sql= "select   *   from   first ";  
ResultSet   rs=stmt.executeQuery(sql);  
while(rs.next())   {%>  
您的第一个字段内容为: <%=rs.getString(1)%>  
您的第二个字段内容为: <%=rs.getString(2)%>  
<%}%>  
<%out.print( "数据库操作成功,恭喜你 ");%>  
<%rs.close();  
stmt.close();  
conn.close();  
%>  
</body>  
</html>
但是我执行的时候确老是出错如下:
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:   Exception   in   JSP:   /first.jsp:5

2:   <%@   page   import= "java.sql.* "%>  
3:   <html>  
4:   <body>  
5:   <%Class.forName( "com.jdbc.mysql.Driver ").newInstance();  
6:   String   url   = "jdbc:mysql://localhost/first?user=test&password=123456&useUnicode=true&characterEncoding=8859_1 ";  
7:   //first&Icirc;&ordf;&Auml;&atilde;&micro;&Auml;&Ecirc;&yacute;&frac34;&Yacute;&iquest;&acirc;&Atilde;&ucirc;  
8:   Connection   conn=   DriverManager.getConnection(url);  


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
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)


root   cause  

javax.servlet.ServletException:   com.jdbc.mysql.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
org.apache.jsp.first_jsp._jspService(first_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.