944,123 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 555
  • Java RSS
Oct 20th, 2009
0

JDBC not recognizing ResultSet assingment (?)

Expand Post »
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:
Java Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 31
Solved Threads: 4
Junior Poster in Training
eggmatters is offline Offline
67 posts
since Nov 2008
Oct 20th, 2009
0
Re: JDBC not recognizing ResultSet assingment (?)
I encapsulated the above code into a class method, surrounded by a try-catch block. That worked
Reputation Points: 31
Solved Threads: 4
Junior Poster in Training
eggmatters is offline Offline
67 posts
since Nov 2008
Oct 21st, 2009
0
Re: JDBC not recognizing ResultSet assingment (?)
> data[i][k + 1] = new Boolean(false);

Better yet; data[i][k + 1] = Boolean.FALSE . Same result, no unnecessary object creation.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Oct 21st, 2009
0
Re: JDBC not recognizing ResultSet assingment (?)
Click to Expand / Collapse  Quote originally posted by ~s.o.s~ ...
> 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.
Reputation Points: 31
Solved Threads: 4
Junior Poster in Training
eggmatters is offline Offline
67 posts
since Nov 2008
Oct 21st, 2009
0
Re: JDBC not recognizing ResultSet assingment (?)
> 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.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Run a function automatically
Next Thread in Java Forum Timeline: hibarnate Bi-directional associations





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC