jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Suggestions for - read text from a txt file and dump into Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Suggestions for - read text from a txt file and dump into Database" Watch "Suggestions for - read text from a txt file and dump into Database" New topic
Author

Suggestions for - read text from a txt file and dump into Database

justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Hi !

I am trying to make some code which will read text from a file and then dump it into MySQL database. It seems to be quite easy
and there are plenty of samples around to learn from and make code that does the job.

Now, the problem is that I want to see what are the different possible ways in which one could do this thing and which would be the best way.
I welcome all suggestions.

Thanks.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29237
    
139

Maybe you could share what you've learned about different approaches? There isn't going to be "one best way", but we could comment on tradeoffs for what you are considering.

Showing you've done this research helps people provide better answers. Otherwise you are left with:
1) Read file
2) Write JDBC

Clearly this is too high level to answer your question


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Jeanne Boyarsky wrote:Maybe you could share what you've learned about different approaches? There isn't going to be "one best way", but we could comment on tradeoffs for what you are considering.

Showing you've done this research helps people provide better answers. Otherwise you are left with:
1) Read file
2) Write JDBC

Clearly this is too high level to answer your question


Okay. I will come back with some concrete answers.


But for now, I will say that I might have to dump a lot of values 10k-25k into a DB. So, certainly this approach won't work:
1- create string
2- reassign the word being read to that string.
3- dump the string into the appropriate place in the DB.

Best alternative to the above - String Builder ?

Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1456
    
    5

Even going further, how about reading records in a chunk and inserting in DB? Or having two threads - one will keep on reading the records, and another would keep on inserting in DB?

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Anayonkar Shivalkar wrote:Even going further, how about reading records in a chunk and inserting in DB? Or having two threads - one will keep on reading the records, and another would keep on inserting in DB?

I hope this helps.


Thanks. I will try to do that too.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Suggestions for - read text from a txt file and dump into Database
 
Similar Threads
Reading very large file
File updation
Printing out a lot of Text to the Screen without Using a lot of <println()>s
How to read the DESede encrypted value using a Java Program
Data File Format & Schema File