<table border="1"> <tr> <% //Add column names to the table while(rsColumns.next()){%> <td><%= rsColumns.getString("COLUMN_NAME") %></td> <%} %> </tr> <% Statement statement =dBBeanId.getConn().createStatement(); ResultSet rs = statement.executeQuery( "select * from" + tableName); //Get column count int columnCount =rs.getMetaData().getColumnCount(); //Store rows to rowData while(rs.next()){ out.println("<tr>"); for(int i =0;i<columnCount;i++){%> <td><%= rs.getObject(i+1) %></td> <% } out.println("</tr>"); } %> </table>
严重: サーブレット jsp の Servlet.service() が例外をスローしました
com.mysql.jdbc.Exceptions.jdbc4.MySQLSyntaxErrorException: SQL 構文にエラーがあります。 MySQL サーバーのバージョンに対応するマニュアルで、1 行目「from_buses」付近で使用する正しい構文を確認してください。sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInst ance(出典不明)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(不明なソース)
java.lang.reflect.Constructor.newInstance(不明なソース)
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.BrowseTable_jsp._jspService(BrowseTable_jsp.java:102)
org.apache.jasper .runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) )
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet .service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) で
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) で
org.apache.catalina.core.StandardHostValve で.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) で
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) で
org.apache.coyote.http11.Http11Protocol で$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
回复讨论(解决方案)
似乎是故from后面少了空格
"select * from" + tableName);
-----------------------------------
"select * from " + tableName);