This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes using a ResultSet with setxxx Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "using a ResultSet with setxxx" Watch "using a ResultSet with setxxx" New topic
Author

using a ResultSet with setxxx

myriah wind
Greenhorn

Joined: Mar 04, 2005
Posts: 14
i'm trying to persist jdbc data from a ResultSet and have this for a problem:
class Collector extends Thread {
...
DateWriter writer = new DateWriter ();
String selectQuery = "SELECT * from xxxData";
+ "WHERE "
+ "serv_prov_type_id == 'BC'";
Statement stmt = con.createStatement();
rset = stmt.executeQuery(selectQuery);

//writer is an instance of DateWriter
// DateWriter is the class that starts Colector
writer.setUniqueMessageChid(String.valueOf(now));
writer.setMessageDateTime(date);

int col = 0;
while(rset.next()) {
rows++;

uid = rset.getInt(1);
pers_id = rset.getInt(2);
serv_prov_type_id = rset.getInt(3);
writer.setPers_id(rows, uid, pers_id); // error
name_last = rset.getString(4);
name_1st = rset.getString(5);
name_cmmn = rset.getString(6);
sex = rset.getString(7);
born_date = rset.getDate(8);
}
writer.getMessageDateTime(); //this works

the error is thrown only within the loop.
StringBuffer.<init>(String) line: 145 [local variables unavailable]

does anyone know what's going on here??? better yet how to make it work?
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Myriah

writer.setPers_id(rows, uid, pers_id); // error

If this line is giving error then possibily the is a problem in setPers_id method in DateWriter class.

can you provide code of same

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Please follow the naming convention


writer.setPers_id(rows, uid, pers_id);


should be like


writer.setPersId(rows, uId, persId);


And can you please print the whole stack trace?
myriah wind
Greenhorn

Joined: Mar 04, 2005
Posts: 14
public void setPers_id(int rows, int uid, String persId); {
natPersId[index] = "XX:"+uid+":"+persId+":08";
}
is the method.
I'm getting StringBuffer.<init>(String) line: 145 [local variables unavailable] message out of WebSphere Studio's debugging facility.
just running it produces a java.lang.NullPointerException

it behaves the same even if I hard cose values into
setPers_id(123, 456, "rnp");
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using a ResultSet with setxxx
 
Similar Threads
Nested Reslutsets
Connection to Oracle Database
junk values written into a file when column values taken from the database table..
JDBC VRE 2.0 BatchUpdate
JayBird / Firebird nullpointerexception when using getInt()