aspose file tools*
The moose likes JDBC and the fly likes parser integer 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 » Databases » JDBC
Bookmark "parser integer to string" Watch "parser integer to string" New topic
Author

parser integer to string

Mohd Zaki Mohd Salikon
Greenhorn

Joined: Dec 16, 2004
Posts: 27
Hi everybody...
I have the sample codes below. The problem is SQL statement is reading the matrik as a number in the database. I want to convert it as a String because declaration matrik in the database as a Text. Thanks...


try { // execute SQL commands to read students' matrik

String query = "SELECT Matrik FROM Pelajar ";
ResultSet rs = stmt.executeQuery(query);
String dat;
//System.out.println("Membaca data pelajar....");
parent.setteks("Membaca subjek pelajar....");
while (rs.next()) {
dat = rs.getString("Matrik");
if (dat != null)
matrik.addElement(dat);

}
}
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
What kind of number is it? Is it an int, long, float, or double? The Java API provides wrapper classes for each of the primitive types (Integer, Long, Float, Double, etc.). In fact, your numbers may already be wrapped since the Java Collections framework uses Objects and cannot handle primitive types directly. Each of the wrapper classes provide toString() methods to get a textual representation of the number. You should check the Java API documentation for details about how to use these classes. Also, if you are using floating-point numbers, you should check out NumberFormat in order to format the output with the desired number of decimal places.

HTH

Layne


Java API Documentation
The Java Tutorial
Mohd Zaki Mohd Salikon
Greenhorn

Joined: Dec 16, 2004
Posts: 27
Thanks...

I'm using microsoft access as a database. The declaration of matrik is a text. type in the Microsoft Access>Design properties. I got the sample codes that are declare matrik as a number. How to convert it as a String. Is it using Integer.parseInt. The declaration below is the original one that are declare as a number in the microsoft access. Thanks...

int n=matrik.size();
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Although it is not a JDBC question. you can do like this,

new String(n) // where n is int type primitive

or you can do this too,

""+n // where n is int type primitive

cheers.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1129

Adeel,
Excuse me, but I couldn't find the constructor you mention:

in the "javadocs". However, I believe the "valueOf()" method (in class "String") may be more suitable. Check the "javadocs" for more details.

Good Luck,
Avi.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874

in the "javadocs". However, I believe the "valueOf()" method (in class "String") may be more suitable. Check the "javadocs" for more details.
<hr></blockquote>

Avi I am really very sorry and I apologize to all beginners especially. It is definitely my fault. I am , its really a silly mistake.

Need not checking javadocs. You said, I agreed .
[ January 17, 2005: Message edited by: Adeel Ansari ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parser integer to string