用jdbc连mysql数据库出现 table doesn't exist 的问题
代码:<%StringdriverName="com.mysql.jdbc.Driver";StringuserName="root";StringuserPasswd=...
代码:
<%
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPasswd="admin";
String dbName="mydb";
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String username = request.getParameter("ID") ;
String password = request.getParameter("password") ;
String sql="SELECT * FROM user WHERE userid='" + username + "' and password='" + password + "'" ;
ResultSet rs = statement.executeQuery(sql);
ResultSetMetaData rmeta = rs.getMetaData();
if ( rs.next ( ) )
out.print ("1") ;
else
out.print ( "0" ) ;
rs.close();
statement.close();
connection.close();
报错信息:
严重: Servlet.service() for servlet jsp threw exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mydb.user' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
。。。。 展开
<%
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPasswd="admin";
String dbName="mydb";
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String username = request.getParameter("ID") ;
String password = request.getParameter("password") ;
String sql="SELECT * FROM user WHERE userid='" + username + "' and password='" + password + "'" ;
ResultSet rs = statement.executeQuery(sql);
ResultSetMetaData rmeta = rs.getMetaData();
if ( rs.next ( ) )
out.print ("1") ;
else
out.print ( "0" ) ;
rs.close();
statement.close();
connection.close();
报错信息:
严重: Servlet.service() for servlet jsp threw exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mydb.user' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
。。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |