Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parser integer to string

 
Mohd Zaki Mohd Salikon
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mohd Zaki Mohd Salikon
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic