1

Before i post my question,i tried all solutions but i can not resolve my problem.Can any one help me to find the solution ?

I m trying to get data from table "Email" but each time it invokes this exception

java.sql.SQLException: ResultSet is TYPE_FORWARD_ONLY at org.sqlite.jdbc4.JDBC4ResultSet.first(JDBC4ResultSet.java:402) at HMDao.EmailDao.FindString(EmailDao.java:144) at hmproject.StartingController.initialize(StartingController.java:103) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at hmproject.HMProject.start(HMProject.java:34) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)

This is my code :

 public Email FindString(String ID) {

        Email email = null;

        String querySelectEmployer = "SElECT Email,Password FROM Email";

        try {

            ResultSet resultSet = Dbaconnection.getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).executeQuery(querySelectEmployer);


            if (resultSet.first()) {

                email = new Email(resultSet.getString("Email"), resultSet.getString("Password"));
            }
            resultSet.close();

        } catch (SQLException ex) {
            ex.printStackTrace();
        }

        return email;

    }

1 Answer 1

3

This happens because first() refers to an "absolute position" within the data set, which is available only for cursor result sets.

Since you do not need repositioning, only moving the cursor to the initial record, replacing the call of first() with next() will do the trick:

if (resultSet.next()) {
    email = new Email(resultSet.getString("Email"), resultSet.getString("Password"));
}
Sign up to request clarification or add additional context in comments.

6 Comments

Perfect answer @dasblinkenlight , but about my password ,i developed an algorithm can encrypt password but i save it like a string in my database,because i have not a feedback about security of application.
@MenaiAlaEddine Even if you encrypt password it is still dangerous. If you use your own encryption scheme, it is likely that it could be broken. Even if you use a proven strong encryption algorithm with a strong key, the key becomes the weak point of the system: if this key is stolen, it becomes possible to decrypt all passwords.
I think,i will use MD5 to encrypt my password,thanks for your advice.
@MenaiAlaEddine Please do not use MD5, use a proven password hash like PBKDF2, bcrypt, etc.
@MarkRotteveel I m using Jasypt.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.