用myeclipes+mysql+Tomcat进行配置,执行程序时显示错误,求大神帮忙

<%@ 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)


风骚小王子
浏览 2708回答 3
3回答

太白金星有点黑

请这位同学在select * from的from后面添加一个空格

忘性最大的人

sql语句构建是需要;符号的,你的select语句最后应该再加一个";"
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL