- 爱易网页
-
Java教程
- 求救!JSP数据库有关问题
日期:2014-05-18 浏览次数:20739 次
求救!JSP数据库问题!
我用的数据库是MYSQL,新建了一个数据库叫JOB 其中有一个表叫User,里面有用户名User_ID,密码PassWD,昵称NickName三个属性。做了一个登录框,让用户输入帐号和密码,如果输入的帐号和密码存在,就打印出用户名(因为只是想测试一下数据库的使用)。可是运行出错了错误信息如下:
An error occurred at line: 9 in the jsp file: /Login.jsp
Generated servlet error:
connection cannot be resolved
An error occurred at line: 9 in the jsp file: /Login.jsp
Generated servlet error:
sqlstring cannot be resolved
An error occurred at line: 9 in the jsp file: /Login.jsp
Generated servlet error:
User_ID cannot be resolved
An error occurred at line: 9 in the jsp file: /Login.jsp
Generated servlet error:
PassWD cannot be resolved
An error occurred at line: 9 in the jsp file: /Login.jsp
Generated servlet error:
sqlstring cannot be resolved
An error occurred at line: 9 in the jsp file: /Login.jsp
Generated servlet error:
connection cannot be resolved
我的源代码如下:
<%@ page contentType= "text/html; charset=gb2312 " %>
<%@ page language= "java " %>
<%@ page import= "com.mysql.jdbc.Driver " %>
<%@ page import= "java.sql.* " %>
<%
String susername = request.getParameter( "User ");
String spassword = request.getParameter( "Password ");
//驱动程序名
String driverName= "com.mysql.jdbc.Driver ";
//数据库用户名
String userName= "root ";
//密码
String userPasswd= "1 ";
//数据库名
String dbName= "job ";
//表名
String tableName= "User ";
//联结字符串
String url= "jdbc:mysql://localhost:3306/job ";
Class.forName( "com.mysql.jdbc.Driver ").newInstance();
Connection con=DriverManager.getConnection(url,userName,userPasswd);
Statement statement = connection.createStatement();
sqlstring = "select User_ID,PassWD,NickName from User where susername = ' "+User_ID+ " ' and
spassword= ' "+PassWD+ " ' ";
ResultSet rs = statement.executeQuery(sqlstring);
// 输出用户名
out.print( " <br> <br> <center> <font size=5 color=blue> "+rs.getString( "User_ID ")
+ " </font> <br> <hr width=800 color=gray> </center> ");
out.print( " <br> ");
out.print( "数据库操作成功,恭喜你 ");
rs.close();
statement.close();
connection.close();
%>
请问是哪里错了啊?谢谢
------解决方案--------------------
我们是同命啊 ,老兄!我也是这样的问题,可没人理我们,还是得自己解决啊