Hello I am learning how to use setString() for "?" and using

passwords in resultsets.
my password ends up with the error

java.sql.SQLException: Invalid cursor state - no current 

row.

Can this error be corrected?
thanks.

run:
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in  connect of the ConnectDerbyDAO
returns isConnected: true
shutdown database 
disconnected after  building the database 

java.sql.SQLNonTransientConnectionException: Database 

'schoolofdb' shutdown.
disconnected after building the database
input from splash: user: sj
in LoginInfoBean
LoginInfoBean password: [C@1428ea
LoginInfoBean user: sj
LoginInfo: user: sj
LoginInfo profile: stu_
all models (Student.java extend LoginInfo.javaall beans extend 

models
in getConnection of DerbyDAOFactory
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in  connect of the ConnectDerbyDAO
returns isConnected: true

In ConnectStudent.select(newUser,newPassword)
param passed: select(): newUser: sj newPassword: [C@1428ea

studentPassword: SELECT stu_password FROM student WHERE 

stu_uid=?
ResultSet rs= : 

org.apache.derby.impl.jdbc.EmbedResultSet40@19113f8
May 18, 2010 5:40:38 AM view.SchoolJDesktopPane login
SEVERE: null
java.sql.SQLException: Invalid cursor state - no current row.
public StudentBean select(String newUser, char[] newPassword) 

throws UnknownSubscriberException, IncorrectPasswordException, 

LoginException, SQLException, FileNotFoundException, IOException 

{
        DerbyDAOFactory ddf = new DerbyDAOFactory();
        conn = ddf.getConnection();
        System.out.println("");
        System.out.println("In 

ConnectStudent.select(newUser,newPassword)");
        System.out.println("param passed: select(): "
                + "newUser: " + newUser + " newPassword: " + 

newPassword);
        System.out.println("");
        ps = 

conn.prepareStatement(ModelUtils.getXMLResource("studentPassword

"));
        System.out.println("studentPassword: 

"+ModelUtils.getXMLResource("studentPassword"));
        [b]ps.setString(1, newUser);<--------------------[/b]
        ResultSet rs = ps.executeQuery();
        System.out.println("ResultSet rs= : "+rs.toString());
        String password = rs.getString(1);
        System.out.println("password from db: "+password);
        if (!password.equals(newPassword)) {
            ps.close();
            rs.close();
            System.out.println("getPassword() is not equal to 

rs.getString(2)");
            throw new IncorrectPasswordException();
        } else {
            ps.close();
            rs.close();
            ps = (PreparedStatement) conn.prepareStatement(
                    ModelUtils.getXMLResource("SelectStudent"));
            ps.setString(1, newUser);
            System.out.println("SelectStudent: "
                    + "\n" + 

ModelUtils.getXMLResource("SelectStudent"));
            rs = ps.executeQuery();
            studentUser.setUser(rs.getString(1));
            studentUser.setPassword(rs.getString(2));
            studentUser.setlName(rs.getString(3));
            studentUser.setmName(rs.getString(4));
            studentUser.setfName(rs.getString(5));
            System.out.println("rs.getString(5): " + 

studentUser.getfName());
            studentUser.setGender(rs.getString(6));
            studentUser.setStartDate(rs.getDate(7));
            studentUser.setEndDate(rs.getDate(8));
            studentUser.setAge(rs.getInt(9));
            studentUser.setAddress(rs.getString(10));
            studentUser.setState(rs.getString(11));
            studentUser.setZip(rs.getInt(12));
            studentUser.setAreaCode(rs.getInt(13));
            studentUser.setPhone(rs.getInt(14));
            studentUser.setPayRate(rs.getDouble(15));
            ps.close();
            rs.close();
        }

Recommended Answers

All 2 Replies

This

ps.setString(1, newUser);<--------------------

is not your problem. This

ResultSet rs = ps.executeQuery();
        System.out.println("ResultSet rs= : "+rs.toString());
        String password = rs.getString(1);

is your problem. You have not called next() (or first()/last()/etc. for scrollable resultsets) before calling getString() so the current "cursor position" is before the first row, i.e. not yet on any row, hence the failure.

What was it you saw that made you think the PreparedStatement's setString was were the exception rather than the ResultSet's getString method?

Thanks

I am not accustomed to using setString() and the error message lead me there

now it is starting to makes sense. I will have to try to work that out.

so ps.steString(1,newUser) should populate the table with the newUser var?

I tried

if(rs.next(){
String password=rs.getString(1);
}

password ended as null

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.