JSP登陆问题

来源:百度知道 编辑:UC知道 时间:2024/06/30 10:02:23
<%
String name=request.getParameter("username");
String pass=request.getParameter("pass");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection dbcon=DriverManager.getConnection("jdbc:odbc:grade");
PreparedStatement stat=dbcon.prepareStatement(
"select * from user where username='?' and password='?'");
stat.setString(1,name);
stat.setString(2,pass);
ResultSet result=stat.executeQuery();
if(result.next())
{
out.println("Login Successful");
}
else
{
out.println("Login Error");
}
}
catch(Exception e)
{
out.println(e);
}
%>
这段代码出现了空指针异常!
数据库起了``执行st.executeQuery()抛出
假如?不用点的话出现user附近语法错误!

String name=reque

select * from user where username='?' and password='?' 不用点看看.'?'
改成?

----------------------------------------
你可以这样试一下吗? select * from user where username='数据库里的数' and password='数据库里的数' 执行是否正确

user是SQL里的关键字 建议换个表名 如userInfo等!

极有可能是
String name=request.getParameter("username");
String pass=request.getParameter("pass");
这两个变量为空,也就是说request里没有。
楼主好好检查检查?

user在一般数据库中都是关键字,不能这样直接用的,如果表名是user的话,就加上双引号。sql语句改成这样试试:
"select * from \"user\" where username=? and password=?"

数据库语句错了 应该这样写

"select * from user where "+username+"=? and "+password+"=?"

不知道写错没 不过 用加号连接字符串 肯定没错

楼上两位说的对,user是关键字,sql语句中出现user一般都会报语法错误,建议改一下表名