Hi,

I'm having some issues with getting next data from the database, it seemed to be working before, but now it doesn't change the textfields to the next data just appends the data into TextArea1 and TextArea2, the other data TextField1 etc.. Doesn't even change, so I do not know why this is happening. Been trying to figure out I can get the next data from the database for about 3 hours would really love some help.Anyone like to shine some light into this?

Thanks

Kru

` private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// Next Button

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null; 



    String host = "xxxx";
    String uName = "xxxx"; 
    String uPass = "xxxx";


    try {
        con = DriverManager.getConnection(host,uName,uPass);

        ps = con.prepareStatement("SELECT * FROM Job",ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        rs = ps.executeQuery();
       // String sql = "SELECT Customer.Firstname,Customer.Surname,Customer.TelephoneNo, ";
        if(rs.next()) {

       int id = rs.getInt("JobID");
       Date date =  rs.getDate("JobDate");
       String status = rs.getString("Status"); 
       String description = rs.getString("Description"); 
       String mechanic = rs.getString("Mechanic");
       Time duration = rs.getTime("Duration");
      // int customer = rs.getInt("CustomerID");
       String txtID = Integer.toString(id);



       jTextField1.setText(txtID);
       jTextField2.setText(date.toString());
       jTextArea1.append(status);
       jTextArea2.append(description);
       jTextField3.setText(mechanic);
       jTextField4.setText(duration.toString());

       System.out.println(id + "" +  date +  status  + description + mechanic +  duration );

        }
        } catch(SQLException e) {

        e.getMessage();

     } finally {
    try {
            if(con != null) {
                con.close();
                 System.out.println("CLOSED!!");
            }      
            if (ps != null) {
                ps.close();
            }
            if(rs != null) {
                rs.close();
            }

        } catch (SQLException e) {
            System.out.println("Exception has been caught");

        }   

    }

}  `

Line 18 if (rs.next... will only execute the following code zero or one times. Didn't you mean
while (rs.next... ?

ps line 43 is a disaster. You get the message string and completely ignore it, so you will never see any error messages. Replace that line with e.printStackTrace(); to see the full details of any diagnostics

Thanks for the reply,

And nope it doesn't seem to work. I have attached pics.

Click Here
Click Here

What is supposed to happen? eg start this form with the first record displayed then move on to the next record each time that ActionPerformed is called? Or something else?

Start the form with the first record (I have another method which does this) then moves on to the next record each time the button is invoked.

In that case your structure is going to have to change. Right now you start again with a new SQL query every time the next button is pressed. You should just do that SQL once, when the form is started, and keep the result set. Then in the button handler you can execute one rs.next() and update all the fields - using setText not append.

Yes, but how do I keep the resultset I mean when I close the rs there won't be anything in the Result set.

Obviously you can't close the result set while the user is trying to "next" his way through it. You need to keep that result set open until the form is closed.

Create window:   do SQL, create result set
Previous/Next:   move through result set, display the current record
Close window:    release all SQL-related resources that were created when the window was opened, including the result set

Thanks Again, James!

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.