<%@ page language="java" import="java.sql.*" contentType="text/html ; chartset=GB2312"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>starting page</title></head><body> 从数据库中读取的数据: <hr> <table border="1"> <tr> <th>用户登录号</th> <th>姓名</th> <th>性别</th> <th>出生日期</th> <th>兴趣爱好</th> </tr> <% String driverName = "com.mysql.jdbc.Driver"; String userName = "root"; String userPasswd = "some_pass"; String dbName = "test"; String tableName = "userinfo"; String url = "jdbc:mysql://localhost:3306/" + dbName; Connection con=null; Statement s; ResultSet rs; Class.forName(driverName); con = DriverManager.getConnection(url,userName,userPasswd); s = con.createStatement(); String sql = "SELECT * From" + tableName; rs = s.executeQuery(sql); while (rs.next()) { out.print("<tr>"); out.print("<td>" + rs.getString("UserId") + "</td>"); out.print("<td>" + rs.getString("Name") + "</td>"); out.print("<td>" + rs.getString("Sex") + "</td>"); out.print("<td>" + rs.getString("BirthDate") + "</td>"); out.print("<td>" + rs.getString("Interest") + "</td>"); out.print("</tr>"); } rs.close(); s.close(); con.close(); %> </table></body></html>以下是网页显示的错误类型异常报告消息 发生处理JSP页面/A1-1.jsp例外在33行说明 服务器遇到阻止其完成此请求内部错误。例外org.apache.jasper.JasperException:发生处理JSP页面/A1-1.jsp例外在33行
30:CON =的DriverManager.getConnection(URL,用户名userPasswd);
31:S = con.createStatement();
32:字符串SQL =“SELECT * FROM”+ tableName值;
33:RS = s.executeQuery(SQL);
34:而(rs.next()){
35:的out.print(“<TR>”);
36:的out.print(“<TD>”+ rs.getString(“用户ID”)+“</ TD>”);
堆栈跟踪:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:579)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)根本原因javax.servlet.ServletException:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:你在你的SQL语法错误; 检查对应于你的MySQL服务器版本在1号线附近使用“Fromuserinfo'正确的语法手册
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
org.apache.jsp.A1_002d1_jsp._jspService(A1_002d1_jsp.java:172)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)根本原因com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:你在你的SQL语法错误; 检查对应于你的MySQL服务器版本在1号线附近使用“Fromuserinfo'正确的语法手册
sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
com.mysql.jdbc.Util.getInstance(Util.java:408)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
org.apache.jsp.A1_002d1_jsp._jspService(A1_002d1_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
添加回答
举报
0/150
提交
取消