为什么我得到" oracle.jdbc.driver.OracleResultSetImpl@3ee82600" ResultSet中的值,而不是Userid和密码

时间:2015-08-03 12:52:59

标签: java jdbc

我使用下面的DAO方法:

    public boolean validate(String UserName,String password) throws Exception
    {
        this.userName=UserName;
        this.password=password;


        boolean status=false;
        PreparedStatement pst = null;
        ResultSet rs = null; 
        Connection con = null;  
        DataBase db =new DataBase();
        con=db.dbConnection();
        User user=new User();
        try {
            pst=con.prepareStatement("select * from login where userId=? and password=?");
            pst.setString(1, user.getUserName());
            pst.setString(2, user.getPassword());
        } catch (SQLException e1) {
            e1.printStackTrace();
        }

        try {
            rs=pst.executeQuery();
            System.out.println("Result in  Resultset"+rs);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            while(rs.next())
            {
                if((rs.getString("USERID")==user.getUserName()) && (rs.getString("Password")==user.getPassword()))
                {           
                    status=true;
                }
                else
                {
                    status=false;
                }
            }
        } catch (SQLException e) {
            System.out.println("Data is not store in result set");
            e.printStackTrace();


    }
        return status;

}

enter image description here

所以这就是我在图片中遇到的问题我得到了这个问题 - " oracle.jdbc.driver.OracleResultSetImpl@3ee82600" ResultSet对象rs中的值,而不是我的数据库中的用户ID和密码

1 个答案:

答案 0 :(得分:2)

您可以通过执行

获取Useridpassword的值
if(rs.next()) {
    String userId = rs.getString("userId");
    String password = rs.getString("password");
}