Forums Register Login

parser integer to string

+Pie Number of slices to send: Send
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);

}
}
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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();
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send

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 ]
A wop bop a lu bop a womp bam boom! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1495 times.
Similar Threads
problen in native sql query execution
connectivity problem
JPQL/ SQL return Entity/ db record
problems with SQL
Two PreparedStatement Object with Same Query
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:26:02.