Help Me... ! String Problem

Hi ,

I have one text file with delimiter as dollar symbol which is imported from one text file.

Now I try to upload the data from this text file into oracle table. Everything inserted properly but one field 揕ocation? values not inserted properly.

The Original Data

1515$$HARRI SMITH$$23/08/2006$$ UNITED KINGDOM $$00:00:48$$23.40

1514$$John$$23/08/2006$$LONDON$$00:00:48$$ 23.40

The table shows like

codeNamedate LocationDuration cost

--

1514John23/08/2006LONDON00:00:4823.40

1515 HARRI SMITH23/08/2006UNITED KINGDOM 00:00:48

if the value of the "Location" is single word it comes properly.

The value of the "Name" come properly. even it has double value.

But Location only the problem when it is double value.

Please give me any one solution !

This is my part of the code :

BufferedReader inn =new BufferedReader(new FileReader("c:\\output.txt"));

while ((lines = inn.readLine()) !=null){

if (!(lines.equals(" "))){

if (!(lines.startsWith("--") || lines.trim().length() <=0 )){

if (!(lines.startsWith(" ") || lines.trim().length() <=0 )){

st =new StringTokenizer(lines,"$$");

code= st.nextToken();

name= st.nextToken();

date = st.nextToken();

location= st.nextToken();

duration = st.nextToken();

cost= st.nextToken();

pstmt = conn.prepareStatement ("insert into tele_report (code,name,r_date, ,location,duration,cost) values (?,?,?,?,?,?)");

pstmt.setString(1,code);

pstmt.setString(2,name);

pstmt.setString(3,date);

pstmt.setString(4,location);

pstmt.setString(5,duration);

pstmt.setString(6,cost);

Please can anybody help me.. !

Thanks

Merlin Roshina

[2315 byte] By [MerlinRosinaa] at [2007-10-3 4:17:24]
# 1
Use String.split instead of the tokenizer.Kaj
kajbja at 2007-7-14 22:19:00 > top of Java-index,Java Essentials,Java Programming...
# 2
... and read the API. You didn't even read what StringTokenizer says about the second String argument and why "$$" won't work.
CeciNEstPasUnProgrammeura at 2007-7-14 22:19:00 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi,The Dollor $$ working properly for all the values except "Loaction"I need fetch the location value and put into a single token or the Location value assigned into a variable.ThanksMerlin Roshina
MerlinRosinaa at 2007-7-14 22:19:00 > top of Java-index,Java Essentials,Java Programming...
# 4
> The Dollor $$ working properly for all the values> except "Loaction"But do you know why it's working for all values except for location?Use String.splitKaj
kajbja at 2007-7-14 22:19:00 > top of Java-index,Java Essentials,Java Programming...
# 5

> The Dollor $$ working properly for all the values

> except "Loaction"

I'm a bit surprised at that, because I'd expect "x$$y" to result in three tokens. I have to admit, I find nothing in the API docs that would indicate that empty tokens are dropped. It only works because they obviously are, since the tokenizer splis up the double dollar, too. It only splits by characters, not by Strings.

CeciNEstPasUnProgrammeura at 2007-7-14 22:19:00 > top of Java-index,Java Essentials,Java Programming...
# 6

Assuming your variables are filled correctly

http://java.sun.com/j2se/1.5.0/docs/api/java/util/StringTokenizer.html#StringTokenizer(java.lang.String, java.lang.String)

why fill out 7 fields with 6 values?

insert into tele_report (code,name,r_date[b], ,[/b]location,duration,cost)

insert into tele_report (1,2,3,,4 ,5,6,7)

values (?,?,?,?,?,?)

values (1,2,3,4,5,6)

Do you see it?

maybe this will help

insert into tele_report (code,name,r_date,NULL ,location,duration,cost)

Or

insert into tele_report (code,name,r_date,DEFAULT ,location,duration,cost)

harmmeijera at 2007-7-14 22:19:00 > top of Java-index,Java Essentials,Java Programming...
# 7
Sorry, that was the field list, you cannot DEFAULT or NULL in a fieldlist.After r_date you have 2 comma's, why?
harmmeijera at 2007-7-14 22:19:00 > top of Java-index,Java Essentials,Java Programming...