Results 1 to 2 of 2
  1. #1
    Dan C is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default reading and writing txt. files into a database

    I am curious to know a method to read a text file I have in my Netbeans project folder. The following code enters the data entered by the user into a text file as well as a text area displayed in the GUI. What I need to understand is how to get these files that are in the Charity donaations.txt to also be placed into a database. I do not understand "yet" but I am learning. Give me some ideas or opinions or if you know a good tutorial I welcome it
    Java Code:
      String name = jTextField1.getText();
            String donation = jTextField2.getText();
            String charity = (String)jComboBox1.getSelectedItem( );
            
         
            String newline = "";
            // appends fields of entry to text area 
            jTextArea1.append(name);
            jTextArea2.append(name + "     ---     " + donation + "     ---     " + charity + "\n" + newline);
            
             try {
                BufferedWriter out = new BufferedWriter(new FileWriter("Charity Donations.txt", true));
    	                
    	           out.write(name + " ");
    	           out.write(charity + " ");
    	           out.write(donation + " ");
    	           
    	           out.newLine();
    	           out.close();
    	 } catch (IOException e) {
    	                System.out.println("There was a problem:" + e);
         }
    Last edited by Dan C; 05-30-2013 at 03:52 AM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: reading and writing txt. files into a database

    You should study the JDBC API; it's a library in the core set of classes that allows you to communicate with a database (with a SQL engine); first you have to define a suitable table (or tables) for your data and next you can write your data to the table(s) or read from it/them.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Try-catch-(finally?) on reading/writing to files
    By Torchi12 in forum New To Java
    Replies: 8
    Last Post: 11-29-2011, 01:42 PM
  2. Reading / Writing files
    By Learning Java in forum New To Java
    Replies: 6
    Last Post: 08-08-2010, 09:21 PM
  3. Reading and Writing Text Files
    By kandt in forum New To Java
    Replies: 1
    Last Post: 11-12-2008, 03:15 AM
  4. Reading/Writing files through Applet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-15-2007, 08:20 PM

Posting Permissions

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