aspose file tools*
The moose likes Java in General and the fly likes How to Convert Long to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to Convert Long to String " Watch "How to Convert Long to String " New topic
Author

How to Convert Long to String

Lijoy John
Ranch Hand

Joined: Jul 24, 2001
Posts: 32
Hi,
Using the ResultSet Object i want to retrieve a data in a column , data type being 'Long'
While (rs.next()){
long ng = 1L;
ng = rs.getLong("Request_Data");
}
out.println(ng);
While doing this i am getting the foll. error:
java.SQLException:failed to convert to internal representation
Kindly let me know how I could print the value to the browser. Is it adbvisable to convert long to string, if yes then how can i proceed.
Any replies would be appreciated.
Thanks,
Regards,
John
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Lijoy,
It doesn't seem to be a printing problem to me. You have placed the variable ng initialization inside of a loop which might be causing the problem because if there is more than one row and the "Request_Data" is not of type long in that row.
If printing if your problem then you can just do the following:
out.println( Long.toString( ng ) );
to get the long into a string.
Regards,
Manfred.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It seems to me there are two main possibilities: (1) the database has column "Request_Data" declared as some type incompatible with long. Check the declared type against this table to determine the best way to access it. Or (2) the driver you use simply doesn't know how to do this conversion properly. Try to find a better driver for your database. Or simply try using other methods like getInt() or getString() - one of them will probably work. For getString() you would then have to use Long.parse() to convert to long, which is less efficient then getting a long to begin with, but if that's what you need to do...
[This message has been edited by Jim Yingst (edited August 03, 2001).]


"I'm not back." - Bill Harding, Twister
Lijoy John
Ranch Hand

Joined: Jul 24, 2001
Posts: 32
Hi Lijoy,
It doesn't seem to be a printing problem to me. You have placed the variable ng initialization inside of a loop which might be causing the problem because if there is more than one row and the "Request_Data" is not of type long in that row.
If printing if your problem then you can just do the following:
out.println( Long.toString( ng ) );
to get the long into a string.
Regards,
Manfred.
Hi Manfred,
Thanks for reply to my query.
I had initialised a long variable and then using that I wanted to store the data by using resultset.getLong("REQUEST_DATA");
I was retrieving 8 fields in total from the database and only this one was causing a problem. It seems that in Oracle the Long datatype is not similar to java long, so that could have been the problem. The datatype defined for REQUEST_DATA is Long and when i used :
String str = resultset.getString("REQUEST_DATA"), i was able to store it in the str variable and print it also.
out.println( Long.toString( ng ) ); is a better way to print the output on the browser.
Thanks for the timely reply and help.
Regards,
John
Lijoy John
Ranch Hand

Joined: Jul 24, 2001
Posts: 32

Hi Jim,
Thanks for replying to my query. I had checked the dataype for the particular column REQUEST_DATA and it is of Long type.To retrieve the data from each column i had been using the getXXX method of the resultset. It seems that Long data type in Oracle and java is not the same as, It worked fine when i used rs.getString() instead of rs.getLong().
Thanking you once again for the timely help and advise given.
Regards,
John
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Convert Long to String