Main Topics
Browse All TopicsHi there,
Could anyone tell me if any sample source that can solve my problem?
I would like to get all the data from the CSV file and then insert it to a table in a Database.
The CSV file format is basically same as a table structure.
Example:
ID FName LName
1 James Knite
1)Read and get data in 2 CSV files, by reference to a Field which exists in both CSV file.
2)The data capture will then be inserted into a table in a Database straight away.
Please advice me how I could go about with this....
Any advice appreciated
Thanks in advance
Kenneth
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
following would allow your csv to be treated a a table allowing you to select from it, then insert into other
https://xlsql.dev.java.net
heaps of database examples here
http://www.javaalmanac.com
you should be able to pick out what you need to do the copy
let me know if you have any questions :)
>>I would like to use pure Java instead of other ready made component/class.
That's OK. Try using String.split to tokenise the CSV file. Bear in mind that there are gotchas with CSV files, which that API treats
String line = null;
BufferedReader in = new BufferedReader(new FileReader("your.csv"));
while ((line = in.readLine()) != null) {
String[] tokens = line.split("\\s*,\\s*");
// Do the insert
}
// Close the Reader
HI,
since my CSV file data are capture from a SQL table, so mean it has Fields name together with its value....SO can I do some filtering like:
when Bac_ID = 1234 then all it's records will be captured and insert into another table in a database
Can I filter that in a CSV file?
Pls advice
Thanks in advance
Kenneth
Output_Filename | BaC_No |
__________________________
F:\sony\1.txt | 222 |
F:\sony\2.txt | 134 |
F:\sony\3.txt | 123 |
F:\sony\4.txt | 123 |
--------------------------
above is the data format in CSV(excel format).
so if i check "Bac_NO=123" then get all to another table will I able to do that? will it get row by row?
thanks
setup your statement
String sql = "INSERT INTO mytable VALUES(?, ?)";
PreparedStatement pstmt = connection.prepareStatemen
then loop thru your file
readLine() will read the next line
then you can parse and chaeck the value
int bac = Integer.parseInt(field[1])
if (bac==123)
{
// insert into database
ps.setObject(1, field(0));
ps.setInt(2, bac);
ps.addBatch();
}
once your done you can execute the batch
ps.executeBatch();
heres some more details on batch inserts
http://www.javaalmanac.com
Let me know if u have any questions :)
Actually I encounter this prb where in my csv files
one of the field actually consists of multiple values.
The 3rd filed in my csv files consists of mulitple values that seperated by "an empty space" or "spacebar".
How am I going to read it and insert it into the table? In each row, one of the field will have mulitple values.
Pls assist me on this prb.
Thanks in advance
Keneth
I'd use http://ostermiller.org/uti
It'll deal with gotchas like that
R94EAJ0000.pdf 2367 "21240949*
21242238*
21242433*
" 9300163309 Form
==========================
Hi above is basically my csv format layout. You possibly can copy and paste into ur Excel Sheet.
The "*" /asterisk is the area where "small box" beside the number is available. (I unable to show the "small box" here so i represent it using "asterisk").
There are 5 fields, and field #3 got 3 sub values on it.
So how am I going to read all this field especially field number 3 which has special character (small box)? Because I gonna append these field's value into db.
I don want to use third party classes.
Thanks
Hope can advice as I desperate for this answer after try n try several times.
Business Accounts
Answer for Membership
by: CEHJPosted on 2006-01-05 at 01:35:30ID: 15616197
http://ostermiller.org/uti ls/CSV.htm l