Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error on get from resultset

 
Gayatri Sinha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

Here is my piece of code


String aa="abs";
Message a = new Message(rs.getString(1), rs.getString(2),abs,rs.getString(3),rs.getString(4));

This gives me a error.

But when I do

String a = rs.getString(3);
String b = rs.getString(4);
String aa="abs";
Message a = new Message(rs.getString(1), rs.getString(2),abs,a,b);

This works fine.

Not able to figure out why though... can anyone help me with this please

Thanks,
 
Masoud Kalali
Author
Ranch Hand
Posts: 531
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gayatri Sinha:
HI,

Here is my piece of code


String aa="abs";
Message a = new Message(rs.getString(1), rs.getString(2),abs,rs.getString(3),rs.getString(4));

This gives me a error.

But when I do

String a = rs.getString(3);
String b = rs.getString(4);
String aa="abs";
Message a = new Message(rs.getString(1), rs.getString(2),abs,a,b);

This works fine.

Not able to figure out why though... can anyone help me with this please

Thanks,


maybe I Can not understand your code , but in second case you used abs as a variable name in constructing the Message alse you declared a twice .

can you tell what is your problem more clearly , then people can help you more easier.
 
Gayatri Sinha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh sorry,

It should be

String aa="abs";
Message msg new Message(rs.getString(1), rs.getString(2),aa,rs.getString(3),rs.getString(4));

This gives me a error.

But when I do

String a = rs.getString(3);
String b = rs.getString(4);
String aa="abs";
Message msg = new Message(rs.getString(1), rs.getString(2),aa,a,b);

The problem I am having is, for "a" and "b", in tthe constructor when I directly use rs.getString() I am getting a error. But when I get them into a String before the constructor and use them, it works fine. Not sure why it happens?

Thanks, hope I am more clear this time
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error? Post it here.

(Some JDBC drivers require you to read the columns in order. But that would cause an exception in the case you say is working, and have no problem in the case you say has an error.)
 
Gayatri Sinha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for getting back so late, I was diggin stuff on the net

The error I am getting is
java.sql.SQLException: ResultSet already closed.

When I am getting the values from the ResultSet rs, into the object Message msg, for one of the values I am also makign a function call.

String sub = "Out of office";
Message msg = new Message(rs.getString("from"), rs.getString("to"), getTransformedSubject(sub), rs.getString("displayName"), rs.getString("ccList"));

I am getting the problem for displayName and ccList.
So if I declare these as variables above and use them, the code works fine, like


String sub = "Out of office";
String displayName = rs.getString("displayName");
String ccList = rs.getString("ccList");

Message msg = new Message(rs.getString("from"), rs.getString("to"), getTransformedSubject(sub), displayName, ccList);

I read somewhere that when using Weblogic, if we make a function call, it automatically closes all the ResultSet? Is this true?
Maybe thats why when I call getTransformedSubject(), the result set closes and I get an sql error for the remaining parameters.

So then this is what I tried, which works fine too..

String sub = "Out of office";
sub = getTransformedSubject(sub);

Message msg = new Message(rs.getString("from"), rs.getString("to"), sub, rs.getString("displayName"), rs.getString("ccList"));


Though my code is working, I am not sure of the reasons..

Thanks
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I am getting the values from the ResultSet rs, into the object Message msg, for one of the values I am also makign a function call.
You didn't mention that in your original post, so now the question is much less mysterious. Posting code that isn't the code that causes the problem is sometimes unhelpful.

Weblogic surely doesn't close result sets when you call a Java method, but it's quite possible that the getTransformedSubject() method has side effects that could include closing your result set. For example it could use the Statement object that generated your result set to generate another result set; this would (as per the API documentation) close your result set.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic