#1
  1. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0

    Quick database q


    When I make a query, and the result set only has 1 value, how would i get it?

    I'm doing this, but I get an error
    Code:
    		ResultSet rs_1 = sql_st.executeQuery(sql_1); // Create result set	
    		sub_uid = rs_1.getInt("user_id");
    Error:
    SQLException: ResultSet.next was not called
  2. #2
  3. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    539
    In the usual way, there is a tutorial on Devshed.com about jsp and db in the JSP series
  4. #3
  5. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    that's where that code came from.
    also, whenever they grabbed the data, it was coming from a while loop. I have no loop, nor do i need one.
    the one instance the tutorial didn't loop, they used getString() everytime. The value i'm pulling isn't a string.
  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Even if you know the resultset has only one row of results, you still have to call rs.next() to get the row pointer to the right place. Then you can use rs.getString() or whatever to get the data.
  8. #5
  9. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Ok, now i'm getting this:
    SQLException: Exhausted Resultset
    My code:
    Code:
    		ResultSet rs_1 = sql_st.executeQuery(sql_1); // Create result set	
    		rs_1.next();
    		sub_uid = rs_1.getInt("user_id");
  10. #6
  11. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Generally you would do something like this if you are expecting a single row
    Code:
    ResultSet rs_1 = sql_st.executeQuery(sql_1); // Create result set
    if(rs_1.next()) {
    	sub_uid = rs_1.getInt("user_id");
    }
    My guess is that your query is returning an empty resultset.
  12. #7
  13. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Ya, I think so too, because when I do that code I get this when I put it in there
    Code:
    An error occurred at line: 3 in the jsp file: /calendar/calendar2/access.jsp
    
    Generated servlet error:
        [javac] Compiling 1 source file
    
    C:\tomcat\work\Standalone\localhost\_\calendar\calendar2\access_jsp.java:88: variable sub_uid might not have been initialized
    		sql_1 = sql_1 + "WHERE j.user_id = " + sub_uid + "\n";
                                                             ^
  14. #8
  15. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Hrm... odd, i changed it so I know i'm getting something back in the result set, but it's still giving me that error.

    And since the script prints out an error and doesn't show anything in the script, I can't find out if the conditional's failing.
  16. #9
  17. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Can you post all your code if it is not too large?
  18. #10
  19. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    I found the problem. I had the wrong column name.

    Also, the data i was entering was faulty.
    THx neway

IMN logo majestic logo threadwatch logo seochat tools logo