Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Required help about the resultset.last()

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Required help about the resultset.last()

    i wanted to get the last staff id from database and generate the lastest staff id..
    but i cannot get the expected result..

    String sql = "SELECT StaffId FROM Staff WHERE StaffId LIKE 'S*';";
            try{
                rsStaffId = stmtQuery.executeQuery(sql);
                while(rsStaffId.next()){
                    //
                        String staffId = rsStaffId.getString(1);
                        int seq = Integer.parseInt(staffId.substring(1, 3));
                        if(rsStaffId.isLast()){
     
                        jtfStaffID.setText("S"+ String.format("%03d",seq+1));
                    }
     
                }
     
     
            }catch(Exception e){
                JOptionPane.showMessageDialog(this, e.toString());
            }


  2. #2
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Required help about the resultset.last()

    i editted the code to bcome...

    String sql = "SELECT LAST(StaffId) FROM Staff WHERE StaffId LIKE 'S*';";
            try{
                rsStaffId = stmtQuery.executeQuery(sql);
                while(rsStaffId.next()){
                    //
     
                        //if(rsStaffId.isLast()){
                        String staffId = rsStaffId.getString(1);
                        //int seq = Integer.parseInt(rsStaffId.getString(1).substring(1, 3));
                        //jtfStaffID.setText("S"+ String.format("%03d",seq+1));
                        jtfStaffID.setText(""+staffId);
                    //}
     
                }
     
     
            }catch(Exception e){
                JOptionPane.showMessageDialog(this, e.toString());
            }


    but i get null in my jtextfield..

Similar Threads

  1. could anybody fix my problem? resultset is closed
    By kagami in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 18th, 2012, 08:18 AM
  2. Resultset for relate table
    By whiga in forum JDBC & Databases
    Replies: 1
    Last Post: May 16th, 2011, 01:04 PM
  3. Dynamically Creating User Selection through ResultSet
    By anmaston in forum Java Theory & Questions
    Replies: 3
    Last Post: April 10th, 2011, 11:08 AM
  4. ResultSet issues
    By _lithium_ in forum JDBC & Databases
    Replies: 3
    Last Post: March 4th, 2011, 02:20 PM
  5. ResultSet is Closed
    By ramayya4u in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: May 24th, 2009, 03:54 AM