JDBC not recognizing ResultSet assingment (?)

Thread Solved

Join Date: Nov 2008
Posts: 63
Reputation: eggmatters is an unknown quantity at this point 
Solved Threads: 4
eggmatters eggmatters is offline Offline
Junior Poster in Training

JDBC not recognizing ResultSet assingment (?)

 
0
  #1
Oct 20th, 2009
Hello all,

I have used this code throughout this application with no troubles. I am creating a datatable, and the data is a result set returned from a sql query to an oracle 11g database. I'm creating a TableModel class that overrides the AbstractTableModel so I can add fetures to it. I get errors when I try to assign my ResultSet object however. Here is the code:
  1. class MyTableModel extends AbstractTableModel {
  2.  
  3. Statement stmt = conn.createStatement();
  4. ResultSet rs;
  5. // the following throws compilation error: "cannot find symbol, symbol: class rs, location class <where it resides in my app> <identifier exepected>
  6.  
  7. rs = stmt.executeQuery(query);
  8.  
  9. //the following is fine:
  10. ResultSetMetaData rsmd = rs.getMetaData();
  11. int numcols = rsmd.getColumnCount();
  12. int numrows;
  13.  
  14. int i = 0;
  15. int k = 0;
  16.  
  17. //rs.next throws the same error as above
  18. while (rs.next()) {
  19. for (k = 0; k <= numcols; k++) {
  20. data[i][k] = rs.getString(k);
  21. }
  22. if (checked) {
  23. data[i][k + 1] = new Boolean(false);
  24. }
  25. i++;
  26.  
  27. }
  28. //Default Table Model overrides follow.

I have no idea why this is not recognizing an object that was created in the line of code right above it, or why rs will auto complete with the expected methods and members but java can't find the package it belongs to.

rs hasn't been declared elsewhere. (It would throw a different error if it had). Any ideas?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: eggmatters is an unknown quantity at this point 
Solved Threads: 4
eggmatters eggmatters is offline Offline
Junior Poster in Training
 
0
  #2
Oct 20th, 2009
I encapsulated the above code into a class method, surrounded by a try-catch block. That worked
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human
 
0
  #3
Oct 21st, 2009
> data[i][k + 1] = new Boolean(false);

Better yet; data[i][k + 1] = Boolean.FALSE . Same result, no unnecessary object creation.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: eggmatters is an unknown quantity at this point 
Solved Threads: 4
eggmatters eggmatters is offline Offline
Junior Poster in Training
 
0
  #4
Oct 21st, 2009
Originally Posted by ~s.o.s~ View Post
> data[i][k + 1] = new Boolean(false);

Better yet; data[i][k + 1] = Boolean.FALSE . Same result, no unnecessary object creation.
HA! I copied that code directly from the sun site. The JDBC / SQL stuff was mine (Although copied from another source initially). I'm not sure however, but the boolean value is meant to represent a checkbox in a Jtable that displays the sql data (I am adding a selection checkbox to the end.) The boolean value needs toreturn its type from a call to getColumnClass() I've overriden. Could that why the created it as an object? Traditinally, there is no such thing as a native "boolean" type.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human
 
0
  #5
Oct 21st, 2009
> Could that why the created it as an object?

There is absolutely no valid reason as to why a Boolean object needs to be created if one already exists and is ready to use i.e. considering that a Boolean can have only two states: TRUE and FALSE and those two are already accounted by the public static fields TRUE and FALSE of the Boolean class.

> Traditinally, there is no such thing as a native "boolean" type.

There is a primitive type "boolean". The usage of the primitive wrapper type Boolean v/s the primitive type boolean boils down to the use case in consideration i.e. whether you have an array of primitives or an array of reference types.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC