Results 1 to 5 of 5
  1. #1
    ryanalhakim is offline Newbies
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default How to read from text file and insert into database using java

    Hi all,

    Please somebody help me, i am newbie in Java. i have questions about java programing, how to read from text file and insert into database.

    I have text file let's say like
    Header
    A123445
    U156664
    A734355
    U835353
    A535355
    Footer

    I wanna be able to read the text file and skip the header and footer, String A means i have to insert the data and String U means i have to update the previous record in database. And i have to parse every string after string A or U. There are 6 strings after A or U. so i want to put into 6 fields in database.

    Please somebody help me. Can we do those things in Java?

    Thanks

    Warmly regards,

    Ryan

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    Java Code:
    while read a line from file
        if line isn't header or footer
            if first letter is A then process Add
            else process Update

  3. #3
    ryanalhakim is offline Newbies
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Java Code:
    while read a line from file
        if line isn't header or footer
            if first letter is A then process Add
            else process Update
    hi sir. thanks so sir. i know the algorithm but i cannot translate that into java code or class.


    ryan

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    hi sir. thanks so sir. i know the algorithm but i cannot translate that into java code or class.
    So what have you done so far? We don't know where to begin to help you, since you have not provided us with any code. Can we assume you know how to make a java class, main method, regular class & instance methods, understand return types, etc etc?

    If so, then the first thing you will need is a database connector. The one for MySQL is MySQL :: Download Connector/J
    and the one for oracle is JDBC/UCP Download Page

    Once you have a JDBC driver, add it to your project, and then you can establish connections using methods described in this tutorial:Establishing a Connection (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics)

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    PS. For file reading, look into the BufferedReader class or the Scanner class. I prefer BufferedReader myself, you would use it like so:
    Java Code:
    BufferedReader in = new BufferedReader(new FileReader(new File("someFile.txt")));
    String line = in.readLine();

Similar Threads

  1. How can we read text file in java 1.4
    By javasaravanan in forum Advanced Java
    Replies: 4
    Last Post: 11-30-2009, 03:28 PM
  2. how to insert sql file into database using swing
    By ravi.virgoo@gmail.com in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 03:01 AM
  3. Replies: 8
    Last Post: 11-06-2009, 06:52 AM
  4. Replies: 1
    Last Post: 10-10-2008, 08:47 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •