'Join' two different field types together into a String - possible in Java?

Not entirely certain whether this is a straightforward Java or more of a JDBC question:

I have two fields, one is a String and one an integer. I need to concatenate these fields together to form one String, prior to performing an insert on a table. ie:

String s = dbRS.getString("partition_name");//get full string

String partstr = s.substring(0, 14);// get first 14 (alpha) characters

int new_partition_number = max_partition_number + 1;//create new unique partition number, incremented by 1

Now I have

- a String (partstr - i.e. "TN1234567890_")

- an integer (i.e. 50)

(NB. The number has to be an integer because it is subject to calculation elsewhere.)

I wish to join these together into a String ("TN1234567890_50") and use the field in an inserted row. I've tried using

String partition_string =new StringBuffer(partstr).append(new_partition_number ).toString();

... but this doesn't work.

I read on a forum that it's impossible to cast an integer to a String in this way in Java, which sounds pretty incredulous from where I am! However my Osborne Java 2 Complete Reference doesn't mention it at all.

Any assistance will be very gratefully received!

Thanks.

[1447 byte] By [speedyvespaa] at [2007-11-27 8:20:16]
# 1
String.valueOf(yourInt);/* OR */Integer.toString(yourInt);
CaptainMorgan08a at 2007-7-12 20:08:33 > top of Java-index,Java Essentials,New To Java...
# 2
Actually I didn't undestand the question, I'm new with java.But, to concatenate a string with an integer try the "+" operator.String newString = partstr + new_partition_number;
Bruno_Grassellia at 2007-7-12 20:08:33 > top of Java-index,Java Essentials,New To Java...
# 3
crosspost : http://forum.java.sun.com/thread.jspa?threadID=5186817&tstart=0
Aknibbsa at 2007-7-12 20:08:33 > top of Java-index,Java Essentials,New To Java...
# 4
wonder why he thinks you can't append an int to a StringBuilder.Works fine. Might of course not yield the expected result depending on expectations, but it works just fine.But then, the coding conventions reminiscent of C don't bode well.
jwentinga at 2007-7-12 20:08:33 > top of Java-index,Java Essentials,New To Java...