新手简单问题 mysql连接问题.....

llsljh 2005-03-10 09:39:55
下边是原代码


<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("mysql://localhost:3306/user","root","llsljh");
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from user";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
</body>
</html>


运行后出错! 为什么 第5行有错误?
错误如下:
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

An error occurred at line: 5 in the jsp file: /1.jsp
Generated servlet error:
url cannot be resolved

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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

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

Apache Tomcat/5.5.8
...全文
152 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
magie16036936 2005-03-10
  • 打赏
  • 举报
回复
也不知道你是从那里粘贴来的~url没有定义没有看出来吗?
Connection conn 为什么要定义两遍呢`
把这个:Connection con = DriverManager.getConnection("mysql://localhost:3306/user","root","llsljh");
改成:
String url="jdbc:mysql://localhost:3306/user?user=root&password=llsljh&useUnicode=true&characterEncoding=8859_1";
tangqiuzheng 2005-03-10
  • 打赏
  • 举报
回复
上GOOGLE搜索: HTTP 500

以下是部分搜索结果:

http://support.microsoft.com/?kbid=311766&ln=zh-cn
leeloolilu 2005-03-10
  • 打赏
  • 举报
回复
我给你写个代码 测试测试

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%

Statement stmt=null;
ResultSet rs = null;

Class.forName("com.mysql.jdbc.Driver").newInstance();

try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/new?user=root&password=llsljh");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from user");

while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
<br> 您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你\n");%>
<%rs.close();
stmt.close();
conn.close();
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
%>

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧