| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5593 人关注过本帖
标题:jsp 连接 mysql 报错,是否空记录引起的啊?
只看楼主 加入收藏
ashimaxigo
Rank: 2
等 级:论坛游民
帖 子:29
专家分:17
注 册:2012-12-24
结帖率:75%
收藏
 问题点数:0 回复次数:0 
jsp 连接 mysql 报错,是否空记录引起的啊?
错误代码如下:
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: An exception occurred processing JSP page /sssss.jsp at line 11

8: Connection conn= DriverManager.getConnection(url);
9: Statement stmt=conn.createStatement();
10: String query="select user_name from user_sys order by id";
11: ResultSet rs=stmt.executeQuery(query);
12: while(rs.next())
13: {
14:         String s=rs.getString("field_name");//看准你的字段是不是字符型,不然就不能用getString,根据字段类使用getBoolean等等


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

root cause

javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'id' in 'order clause'
 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
 org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
 org.apache.jsp.sssss_jsp._jspService(sssss_jsp.java:79)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
 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)

root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'id' in 'order clause'
 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
 com.mysql.jdbc.Util.getInstance(Util.java:381)
 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
 com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
 com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
 com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
 com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
 com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)
 org.apache.jsp.sssss_jsp._jspService(sssss_jsp.java:64)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
 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.13 logs.

源码如下:
<%@ 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/gzpsys?user=root&password=123456&useUnicode=true&characterEncoding=GB2312" ;
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String query="select user_name from user_sys order by id";
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
        String s=rs.getString("field_name");//看准你的字段是不是字符型,不然就不能用getString,根据字段类使用getBoolean等等
        out.print(s+"<br>");
}
%>
</body>
</html>
数据表见附件。表内无数据
图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: occurred server mysql 记录 
2014-10-01 22:59
快速回复:jsp 连接 mysql 报错,是否空记录引起的啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049317 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved