aspose file tools*
The moose likes JDBC and the fly likes error on get from resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "error on get from resultset" Watch "error on get from resultset" New topic
Author

error on get from resultset

Gayatri Sinha
Ranch Hand

Joined: Feb 13, 2006
Posts: 34
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

Joined: Jul 08, 2004
Posts: 531

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.


Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
Gayatri Sinha
Ranch Hand

Joined: Feb 13, 2006
Posts: 34
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
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

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

Joined: Feb 13, 2006
Posts: 34
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
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error on get from resultset
 
Similar Threads
references and objects
Error Retreiving a resultset from an oracle stored procedure
instanceof key word
doubt in casting
how to improve my program code ?