jsp连接数据库的问题请教
小弟刚开始学习,jsp连接mysql数据库出现问题 ,各位高手帮下忙吧,问题出在哪呢?
代码:
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%
String driverName = "com.mysql.jdbc.Driver";
String userName = "root";
String userPasswd="root";
String dbName="sss";
String tableName="ssssin";
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver" ).newInstance();
Connection conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String sql="SELECT*FROM" +tableName;
ResultSet rs=stmt.executeQuery(sql);
ResultSetMetaData rmeta=rs.getMetaData();
int numColumns=rmeta.getColumnCount();
out.print("id");
out.print("name");
while(rs.next())
{
out.print(rs.getString(1));
out.print(rs.getString(2));
}
out.print("数据库操作成功");
out.print("<center>");
rs.close();
stmt.close();
conn.close();
%>
报错:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /5.jsp:18
15: Connection conn=DriverManager.getConnection(url);
16: Statement stmt=conn.createStatement();
17: String sql="SELECT*FROM" +tableName;
18: ResultSet rs=stmt.executeQuery(sql);
19: ResultSetMetaData rmeta=rs.getMetaData();
20: int numColumns=rmeta.getColumnCount();
21: out.print("id");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.ServletException: 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 'FROMssssin' at line 1
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp._5_jsp._jspService(_5_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.sql.SQLException: 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 'FROMssssin' at line 1
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
com.mysql.jdbc.Statement.executeQuery(Statement.java:822)
org.apache.jsp._5_jsp._jspService(_5_jsp.java:63)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
是环境配置的原因还是什么原因,该怎么解决呢? 希望哥哥姐姐们给解释下