<%@ page contentType="text/html; charset=gb2312" %> <%@ page language="java" %> <%@ page import="org.gjt.mm.mysql.*" %> <%@ page import="java.sql.*" %><%@ page import="java.util.*" %><% //驱动程序名 String driverName="org.gjt.mm.mysql.Driver"; //数据库用户名 String userName="root"; //密码 String userPasswd="123"; //数据库名 String dbName="owner"; //表名 String tableName="userinfo"; //联结字符串 String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd; Class.forName("org.gjt.mm.mysql.Driver").newInstance(); Connection connection=DriverManager.getConnection(url); Statement statement = connection.createStatement(); String sql="select * from" +tableName; ResultSet rs=statement.executeQuery(sql); //获得数据结果集合 ResultSetMetaData rmeta = rs.getMetaData(); //确定数据集的列数,亦字段数 int numColumns=rmeta.getColumnCount(); // 输出每一个数据值 out.print("name"); out.print("|"); out.print("passwd");
out.print("|");
out.print("permit"); out.print("<br>"); while(rs.next()) { out.print(rs.getString(1)+" "); out.print("|"); out.print(rs.getString(2)+" "); out.print("|");out.print(rs.getString(3)); out.print("<br>"); } out.print("<br>"); out.print("数据库操作成功,恭喜你"); rs.close(); statement.close(); connection.close(); %> 代码如上昨天还好好的,今天就报错了.HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage 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 /testmysql.jsp at line 4542: 
43: String sql="select * from" +tableName; 
44: 
45: ResultSet rs=statement.executeQuery(sql); 
46: 
47: //获得数据结果集合 
48: 
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.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fromuserinfo' at line 1
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.testmysql_jsp._jspService(testmysql_jsp.java:157)
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.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fromuserinfo' at line 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
com.mysql.jdbc.Connection.execSQL(Connection.java:3250)
com.mysql.jdbc.Connection.execSQL(Connection.java:3179)
com.mysql.jdbc.Statement.executeQuery(Statement.java:1207)
org.apache.jsp.testmysql_jsp._jspService(testmysql_jsp.java:100)
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.
--------------------------------------------------------------------------------Apache Tomcat/6.0.13