当前位置: 技术问答>java相关
:( jsp连接mysql数据库错误!
来源: 互联网 发布时间:2017-03-11
本文导语: 在JSP+Tomcat3.3.1+Mysql环境中,连接数据库时出错,急!!! class设置: classpath=.;%JAVA_HOME%bin;%JAVA_HOME%jrebin;d:tomcat3.3.1lib; jdbc文件位置: d:tomcat3.3.1libmm.mysql-2.0.14-bin.jar jsp代码: ... java.lang.String strCon; Class.forName("org.gjt.mm...
在JSP+Tomcat3.3.1+Mysql环境中,连接数据库时出错,急!!!
class设置:
classpath=.;%JAVA_HOME%bin;%JAVA_HOME%jrebin;d:tomcat3.3.1lib;
jdbc文件位置:
d:tomcat3.3.1libmm.mysql-2.0.14-bin.jar
jsp代码:
...
java.lang.String strCon;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
sqlCon= java.sql.DriverManager.getConnection("jdbc:mysql://localhost/cwt");
...
错误信息:
Error: 500
Location: /myweb/cwt/manager/techadd.jsp
Internal Servlet Error:
javax.servlet.ServletException: org.gjt.mm.mysql.Driver
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:460)
at cwt.manager.techadd_3._jspService(techadd_3.java:218)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Root cause:
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at org.apache.tomcat.util.depend.DependClassLoader.loadClassInternal1(DependClassLoader.java:186)
at org.apache.tomcat.util.depend.DependClassLoader12$1.run(DependClassLoader12.java:92)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.tomcat.util.depend.DependClassLoader12.loadClass(DependClassLoader12.java:90)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at cwt.manager.techadd_3._jspService(techadd_3.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
class设置:
classpath=.;%JAVA_HOME%bin;%JAVA_HOME%jrebin;d:tomcat3.3.1lib;
jdbc文件位置:
d:tomcat3.3.1libmm.mysql-2.0.14-bin.jar
jsp代码:
...
java.lang.String strCon;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
sqlCon= java.sql.DriverManager.getConnection("jdbc:mysql://localhost/cwt");
...
错误信息:
Error: 500
Location: /myweb/cwt/manager/techadd.jsp
Internal Servlet Error:
javax.servlet.ServletException: org.gjt.mm.mysql.Driver
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:460)
at cwt.manager.techadd_3._jspService(techadd_3.java:218)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Root cause:
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at org.apache.tomcat.util.depend.DependClassLoader.loadClassInternal1(DependClassLoader.java:186)
at org.apache.tomcat.util.depend.DependClassLoader12$1.run(DependClassLoader12.java:92)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.tomcat.util.depend.DependClassLoader12.loadClass(DependClassLoader12.java:90)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at cwt.manager.techadd_3._jspService(techadd_3.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
|
jsp连接MySQL数据库
testmysql.jsp如下:
您的第一个字段内容为:
您的第二个字段内容为:
testmysql.jsp如下:
您的第一个字段内容为:
您的第二个字段内容为:
|
Class.forName("org.gjt.mm.mysql.Driver");
Connection sqlCon= DriverManager.getConnection("jdbc:mysql://localhost:3306/cwt",username,passwd);
默认情况下Mysql的端口是3306.
Connection sqlCon= DriverManager.getConnection("jdbc:mysql://localhost:3306/cwt",username,passwd);
默认情况下Mysql的端口是3306.
|
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
sqlCon== DriverManager.getConnection("jdbc:mysql://ip:://localhost:3306/cwt?user=你的用户名&password=你的密码&useUnicode=true&characterEncoding=gb2312");
sqlCon== DriverManager.getConnection("jdbc:mysql://ip:://localhost:3306/cwt?user=你的用户名&password=你的密码&useUnicode=true&characterEncoding=gb2312");
|
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=15371