How to pass values to database table?
Hi, people!
I need to parse values from textfile lines, and make sql for inserting that values into appropriate table. Each line has a form that looks like this one:
IdNum=xxxx;Name=抶x...x?Address=抶x...x?[LocalNum=xxxx;]Type=抶?
where IdNum, Name, Address, LocalNum and Type are name of columns, xxx are values and value in [ ] is optional columnname=value (columnname can have null values).
I managed to parse names of colums and values. Here is the code:
import java.util.*;
publicclass Strtok{
publicstaticvoid main(String [] args){
String str ="IdNum=xxxx;Name=抶x...x?Address=抶x...x?LocalNum=xxxx;Type=抶?";
StringTokenizer token =new StringTokenizer(str ,"= ;");
while (token.hasMoreElements())
System.out.println(token.nextElement());
}
}
and result is:
IdNum
xxxx
Name
抶x...x?br>Address
抶x...x?br>LocalNum
xxxx
Type
抶?br>
Now, how can I pass that values into insert query
INSERT INTO TableNAme (IDNum, Name, Address, LocalNum, Type)
VALUES (xxxx, 'xx...x', 'xx...x', xxxx,'x' );
?

