Read Line by Line from a file and insert into database table likewise

How to read line by line from a file and insert likewise in to database table can be achieved with the help of following block of code.

1. ReadLineInsertLine.java
package readlineinsertline;

import db.Insert;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Sudhanshu
 */
public class ReadLineInsertLine {

    /**
     * @param args the command line arguments
     */
    @SuppressWarnings(“SleepWhileInLoop”)
    public static void main(String[] args) throws IOException, InterruptedException {
         BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(“E://core//io//NB//wiki.txt”)));
        
         Insert in=new Insert();
        
         LineNumberReader lnr = new LineNumberReader(new FileReader(new File(“E://core//io//NB//wiki.txt”)));
         int ln = 0;
         while(lnr.readLine()!=null){           
          ln++;
         }
         lnr.close();
        
         System.out.println(“Total Lines: “+ln+” in “+new Date());
       
         for(int i=0; i             in.insert(++i, br.readLine());
            // System.out.println(i);
             // System.out.println(i+” : “+br.readLine());
           // Thread.sleep(1000);
         }
        
        
        
    }
}
2. Find the database realted programs by clicking here or browing through the blog.
-Read.java
-DBConn.java
-Insert.java
-CreateTable.java
-Query.java

Compile the programs and execute using the main class. Please make sure you have installed mysql server and have mysql connector reference in classpath. Also create a database oxyzium before executing the program.

Database Creation Command:
create database oxyzium;
Write the above statement after login to mysql console.