The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

do like this

Posted by SPIDY on January 18, 2001 at 7:31 AM

> I am a java starter and am trying to write records to an output text file. I am getting these records into a "resultset" ineterface from a database using JDBC.I want to know how can i do the following thing in java:-

> for example say there are two fields per record
> one is String Name
> other is int ID
> what I need to do is that even if the value of String Name is Null i still want to write at least 5 spaces to the output file. Same way even if int ID is null i want to write 3 zeroes into the file. So basically it the question of formatting them.

> e.g example1 String Name = "Sunil"
> int ID = 1234;

> So the output in the text file would be "Sunil1234"

> example2 String Name contains Null
> int ID = 1234;
> So the output file should look like
> " 1234"
> which means there should be five spaces before 1234

>
>
>
>


do like this
if(rs.getString(1).equals("")) {
String name=" ";
}
if(rs.getString(2).equals("")) {
int ID=0;
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us