Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Insert to database from text file

How can i insert into an access database using sql which gets the values from a text file?
0
johnbert_99
Asked:
johnbert_99
  • 2
  • 2
  • 2
  • +1
1 Solution
 
CEHJCommented:
Read as tokens, insert as fields

int fieldNum = 0;
StringTokenizer st = new StringTokenizer(fileLine);
while ( st.hasMOreTokens()) {
  ps.setString(++fieldNum, st.nextToken());
}
0
 
Tommy BraasCommented:
ps in CEHJ's example is a PreparedStatement.
0
 
johnbert_99Author Commented:
can u maybe explain more?....
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
Please give the format of the text file
0
 
Tommy BraasCommented:
A PreparedStatement is an easy  way to add content to a query statement or update/insert statement.

You can find the Javadocs here: http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Reading from a text-file: http://www.javaalmanac.com/egs/java.io/ReadLinesFromFile.html

(you can also have a look at the "Related Examples" and at: http://www.javaalmanac.com/cgi-bin/search/find.pl?words=file)

Inserting a row into a database-table: http://www.javaalmanac.com/egs/java.sql/InsertPs.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Since points are too less to split, accept CEHJ's comment as answer.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now