Solved

Insert to database from text file

Posted on 2004-04-06
10
202 Views
Last Modified: 2010-03-31
How can i insert into an access database using sql which gets the values from a text file?
0
Comment
Question by:johnbert_99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 30 total points
ID: 10767392
Read as tokens, insert as fields

int fieldNum = 0;
StringTokenizer st = new StringTokenizer(fileLine);
while ( st.hasMOreTokens()) {
  ps.setString(++fieldNum, st.nextToken());
}
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10767508
ps in CEHJ's example is a PreparedStatement.
0
 

Author Comment

by:johnbert_99
ID: 10768450
can u maybe explain more?....
0
Technology Partners: 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!

 
LVL 86

Expert Comment

by:CEHJ
ID: 10768460
Please give the format of the text file
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10768585
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 10772057
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 10958438
Since points are too less to split, accept CEHJ's comment as answer.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
null output 3 59
maven module vs maven project 3 120
difference between sorce folder and folder in eclipise 3 65
using executorService 3 25
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question