JDBC 的问题????????
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<%!
String DBDRIVE ="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String DBURL ="jdbc:microsoft:sqlserver://migo:1400;DataBase=usermessage";
String PASSWORD ="sa";
String USERNAME ="sa";
Connection con =null;
PreparedStatement ps =null;
ResultSet rs =null;
%>
<%--接受参数--%>
<%
String name=request.getParameter("uname");
String password=request.getParameter("password");
boolean flag=false;
%>
<%--验证用户--%>
<%
String sql="select userid from userinfo where username=? and userpassword=?";
try
{
Class.forName(DBDRIVE);
//out.print("驱动已加载");
con=DriverManager.getConnection(DBURL,USERNAME,PASSWORD);
//out.print("数据库已连接");
ps=con.prepareStatement(sql);
ps.setString(1,name);
ps.setString(2,password);
rs=ps.executeQuery();
out.print("SQL已执行");
out.print(rs.getRow());
if(rs.next())
{
//将用户名保存在session中
out.print("用户合法");
flag=true;
//session.setAttribute("name",rs.getString(1));
}
else
{
//用户不合法,保存错误信息
out.print("用户不合法");
request.setAttribute("err","错误的用户名或密码");
}
rs.close();
ps.close();
con.close();
}
catch(Exception e){
}
%>
-----------------------------------------------------------------------------------------
以上是我用JDBC连接sqlserver 2000的代码,请问一下各位,为什么我的rs.next()返回的总是0???
ps:我的userinfo表中已存在一条记录,以上代码输出结果总是:
0 用户不合法