JSP连接mysql出现的异常

potatomoon 2010-10-09 10:44:00
我的代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>


<html>
<body>
<div align="center"><strong>数据库连接</strong></div>
<br>
<table width="800" border="1" align="center">
<tr>
<td align="center">用户名称</td>
<td align="center">用户密码</td>
<td align="center">用户权限</td>
</tr>
<%
try{
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPassword="root";
String dbName="test";
String tableName="user";
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPassword;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection(url);
String sql="select * from"+tableName;
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
%>
<tr>
<td align="center"><%=rs.getString("username")%></td>
<td align="center"><%=rs.getString("userpwd")%></td>
<td align="center"><%=rs.getString("userxian")%></td>
</tr>
<%
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>

</tabel>
</body>
</html>

我将代码放在E:\Program Files\Tomcat 6.0\webapps\test中,出现的异常为:
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: Unable to compile class for JSP:


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.

我试着在MyEclipse里运行,同样出现异常,每次启动tomcat的时候没事,但是访问的时候就报错了:
Source not found for JkMain.pause() line: 679


还望高手指点。。。
...全文
179 点赞 收藏 14
写回复
14 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
potatomoon 2010-10-09
MyEclipse控制台信息:
2010-10-9 11:44:14 org.apache.catalina.core.AprLifecycleListener init
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Users\moon\AppData\Local\Genuitec\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;E:\Program Files\Tomcat 6.0\bin
2010-10-9 11:44:14 org.apache.coyote.http11.Http11Protocol init
严重: Error initializing endpoint
java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:141)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:50)
at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:494)
at org.apache.coyote.http11.Http11Protocol.init(Http11Protocol.java:175)
at org.apache.catalina.connector.Connector.initialize(Connector.java:1059)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:578)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:792)
at org.apache.catalina.startup.Catalina.load(Catalina.java:504)
at org.apache.catalina.startup.Catalina.load(Catalina.java:524)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
2010-10-9 11:44:14 org.apache.catalina.startup.Catalina load
严重: Catalina.start
LifecycleException: Protocol handler initialization failed: java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
at org.apache.catalina.connector.Connector.initialize(Connector.java:1061)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:578)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:792)
at org.apache.catalina.startup.Catalina.load(Catalina.java:504)
at org.apache.catalina.startup.Catalina.load(Catalina.java:524)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
2010-10-9 11:44:14 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 751 ms
2010-10-9 11:44:14 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2010-10-9 11:44:14 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.10
2010-10-9 11:44:15 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2010-10-9 11:44:15 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2010-10-9 11:44:15 org.apache.coyote.http11.Http11Protocol start
严重: Error starting endpoint
java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:141)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:50)
at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:494)
at org.apache.tomcat.util.net.JIoEndpoint.start(JIoEndpoint.java:513)
at org.apache.coyote.http11.Http11Protocol.start(Http11Protocol.java:202)
at org.apache.catalina.connector.Connector.start(Connector.java:1132)
at org.apache.catalina.core.StandardService.start(StandardService.java:457)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2010-10-9 11:44:15 org.apache.catalina.startup.Catalina start
严重: Catalina.start:
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
at org.apache.catalina.connector.Connector.start(Connector.java:1139)
at org.apache.catalina.core.StandardService.start(StandardService.java:457)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2010-10-9 11:44:15 org.apache.catalina.startup.Catalina start
信息: Server startup in 995 ms
2010-10-9 11:44:15 org.apache.catalina.core.StandardServer await
严重: StandardServer.await: create[8005]:
java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:373)
at org.apache.catalina.startup.Catalina.await(Catalina.java:616)
at org.apache.catalina.startup.Catalina.start(Catalina.java:576)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
回复
licip 2010-10-09
他这个可能是数据库动太变动的吧。[Quote=引用 7 楼 gouxiongyaya 的回复:]
汗,看了半天才看出来你这错了
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPassword;
mysql里应该是这么用的吧
String url="jdbc:mysql://localhost:3306/test";
Connection con=Driver……
[/Quote]
回复
a619225471 2010-10-09
[Quote=引用 8 楼 jiajunqiang 的回复:]
这句话中form后面少个空格
String sql = "select * from " + tableName;

以后贴异常的时候贴全了,别人也好给你看啊,如果页面看不到就上eclipse的控制台看,或者tomcat的logs/catalina.out里面找
[/Quote]
up
回复
jiajunqiang 2010-10-09
这句话中form后面少个空格
String sql = "select * from " + tableName;

以后贴异常的时候贴全了,别人也好给你看啊,如果页面看不到就上eclipse的控制台看,或者tomcat的logs/catalina.out里面找
回复
gouxiongyaya 2010-10-09
汗,看了半天才看出来你这错了
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPassword;
mysql里应该是这么用的吧
String url="jdbc:mysql://localhost:3306/test";
Connection con=DriverManager.getConnection(url,"root","root");
楼主再试试。。。
回复
whut_lcy 2010-10-09
....................
回复
potatomoon 2010-10-09
在MyEclipse里又出现另一个异常:
Source not found for JspServletWrapper.handleJspException(Exception) line: 483

直接访问http://localhost:8080/test/mysql.jsp时异常没有变
回复
ddzhouqian 2010-10-09
[Quote=引用 2 楼 valen_jia 的回复:]
String sql="select * from "+tableName;
from后面弄个空格
[/Quote]
up
回复
weipj007 2010-10-09
500错误应该是代码有问题。
回复
valen_jia 2010-10-09
String sql="select * from "+tableName;
from后面弄个空格
回复
zyanxia6749girl 2010-10-09
将异常贴进google,页面显示和数据库连接代码最好分开写。
回复
potatomoon 2010-10-09
引用 9 楼 a619225471 的回复:
引用 8 楼 jiajunqiang 的回复:
这句话中form后面少个空格
String sql = "select * from " + tableName;

以后贴异常的时候贴全了,别人也好给你看啊,如果页面看不到就上eclipse的控制台看,或者tomcat的logs/catalina.out里面找

up



up up

下次一定注意,,我把tomcat重装了,成功了!谢谢大家。。。。
回复
JAVASUNING741 2010-10-09
[Quote=引用 9 楼 a619225471 的回复:]
引用 8 楼 jiajunqiang 的回复:
这句话中form后面少个空格
String sql = "select * from " + tableName;

以后贴异常的时候贴全了,别人也好给你看啊,如果页面看不到就上eclipse的控制台看,或者tomcat的logs/catalina.out里面找

up
[/Quote]

up up
回复
ddzhouqian 2010-10-09
JVM_Bind
难道又是端口被占用的问题?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2010-10-09 10:44
社区公告
暂无公告