cHEo
asked on
String Tokenizer
I want to read from a text file which delimiters is tab and construct it as a SQL query string. I have problem when any of the field is empty.
StringTokenizer st = new StringTokenizer(thisLine, "\t"); while (st.hasMoreTokens()){
query = query + "\'" + st.nextToken() + "\'" ;
if(st.hasMoreTokens())
query = query + "," ;
// some other codes
}
mesg = "INSERT into Student_Result (STUID, AGE, SEX, RACE) "+ "values (" + query + ")";
If in the text file, any field is empty, the mesg string will be a problematic sql statement.
Thank you
StringTokenizer st = new StringTokenizer(thisLine, "\t"); while (st.hasMoreTokens()){
query = query + "\'" + st.nextToken() + "\'" ;
if(st.hasMoreTokens())
query = query + "," ;
// some other codes
}
mesg = "INSERT into Student_Result (STUID, AGE, SEX, RACE) "+ "values (" + query + ")";
If in the text file, any field is empty, the mesg string will be a problematic sql statement.
Thank you
ASKER
i tried before to use StringTokenizer(thisLine, "\t", true) but is having problem also. Can u provide me the additional code? thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am not sure if the is what you want but check if the tokens length is 0 then do what ever you wanan do.
ASKER
Objects, I was the one who personally sent email to ask you about other java problem. You are just fantastic. Thank a lot.
StringTokenizer st = new StringTokenizer(thisLine, "\t", true);
This may solve ur problem but need some additional code..