连接数据库成功了,为什么不能查询呢

<%@ page contentType="text/html; charset=UTF-8" import="java.sql.*" %><html> <body> 从MYSQL数据库中读取的数据:<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="";//数据库存取密码 String dbName="test";//数据库名 String tableName="userinfo";//数据库中的表名 String url="jdbc:mysql://localhost/"+"test";//连接数据库的URL Connection con=null; Statement s; ResultSet rs;//声明三类对象 try { Class.forName(driverName).newInstance();//加载JDBC驱动程序 }catch(ClassNotFoundException e) { System.out.print("Error loading Driver,不能加载驱动程序!"); } try { con=DriverManager.getConnection(url, userName,userPasswd);//连接数据库 } catch(SQLException er) {System.out.print("Error getConnection,不能连接数据库!"); } try { s=con.createStatement();//创建statement类对象 String sql="SELECT*FROM"+tableName;//定义查询语句 rs=s.executeQuery(sql);//执行查询,得到查询结果集 while(rs.next()) { out.println("<tr>"); out.println("<td>"+rs.getString("UserId")+"</td>"); out.println("<td>"+rs.getString("Name")+"</td>"); out.println("<td>"+rs.getString("Sex")+"</td>"); out.println("<td>"+rs.getString("BirthDate")+"</td>"); out.println("<td>"+rs.getString("Interest")+"</td>"); out.println("</tr>"); } rs.close();s.close();con.close(); } catch(SQLException er) {System.err.println("Error executeQuery,不能执行查询!");} %> </table> </body></html>执行结果就是第二个图,数据库的内容都查询不出来,为什么呢?图三为数据库内容
应该是这部分的问题吧?

第1个回答  2018-01-02
sql语句格式问题
解决方法:1、select * FROM tableName 空格必须有。2、表名用` tableName`包住本回答被提问者和网友采纳
相似回答