JSP连接Mysql遇到一些问题
我用的是JDBC驱动.去官网上下载了
mysql-connector-java-5.0.7.jar,解压缩
然后配置:
把mysql-connector-java-5.0.7-bin.jar复制到了D:\Java\mysqlforjdbc和
D:\Java\jdk1.5.0\lib两个目录下
编辑了CLASSPATH
%JAVA_HOME%\lib\mysql-connector-java-5.0.7-bin.jar;D:\Java\mysqlforjdbc\mysql-connector-java-5.0.7-bin.jar;
最后建立了一个数据库,名字是first,用户为test,密码为123456
建立一个表名叫about
下面是first.jsp
<%@ page contentType= "text/html;charset=gb2312 "%>
<%@ page import= "java.sql.* "%>
<html>
<body>
<%Class.forName( "org.gjt.mm.mysql.Driver ").newInstance();
String url = "jdbc:mysql://localhost/softforum?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
javax.servlet.ServletException: org.gjt.mm.mysql.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.first_jsp._jspService(first_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:148)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:69)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.first_jsp._jspService(first_jsp.java:47)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
请各位帮帮忙,最好能说的简单点,我是个菜鸟,不好意思啊
先谢谢了
[解决办法]
Class.forName( "org.gjt.mm.mysql.Driver ").newInstance(); 改成
Class.forName( "com.mysql.jdbc.Driver ").newInstance(); 试下
[解决办法]
mysql-connector-java-5.0.7.jar
把它放到你的tomcat\common\lib 下面
或者是你的web程序里面的WEB-INF\lib 下面也可以
classpath 不用配置
Class.forName( "org.gjt.mm.mysql.Driver ").newInstance()这句改一下
Class.forName( "com.mysql.jdbc.driver ").newInstance() 再试试
[解决办法]
lib里面导入mysql对jdbc的驱动就行了呀
[解决办法]
copy到lib目录下啊.
[解决办法]
ISO8859-1
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html