Advertisement
rowifm

SQLReader

Aug 5th, 2015
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. package sqlreader;
  2. import com.csvreader.CsvReader;
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6.  
  7. /**
  8.  *
  9.  * @author NasiPadang
  10.  */
  11. public class SQLReader {
  12.    
  13.     private String value;
  14.     private String SQL;
  15.     void readers(String filepath){
  16.     try{
  17.         File file = new File(filepath);
  18.         System.out.println(filepath);
  19.         System.out.println(file.getCanonicalPath());
  20.         CsvReader reader= new CsvReader(filepath);
  21.         System.out.println(reader.getColumnCount());
  22.         value="";
  23.         reader.readHeaders();
  24.     /*
  25.     Insert your database name and consider the SQL Syntax
  26.     */
  27.         while(reader.readRecord()){
  28.             value ="INSERT INTO ALL_ROW_REPORT_2013 VALUES(";
  29.             for(int i=0;i<17;i++){
  30.             value = value + "'" +reader.get(i)+"',";
  31.                 if(i==16)
  32.                     value = value +"'"+reader.get(i)+"');";                  
  33.             }
  34.         //SQL = ""+value+")";
  35.         System.out.println(value);
  36.         ReaderDAO b = new ReaderDAO();
  37.         try{
  38.             b.connection(value);
  39.             System.out.println("Insert Successfull");}
  40.         catch(Exception e){
  41.             System.out.println(e);}
  42.            
  43.         }
  44.     }
  45.     catch(FileNotFoundException e){
  46.         System.out.println("File Not Found");
  47.         System.out.println(e.getMessage());
  48.     }
  49.    
  50.     catch(IOException ea){
  51.         System.out.println(ea.getMessage());
  52.         System.out.println("File Not Exist");
  53.     }
  54.     }
  55.     /*
  56.     Place your directory here
  57.     */
  58.     void getFile() throws IOException{
  59.    
  60.  
  61.     File folder = new File("C:\\Dir\\");
  62.     System.out.println(folder.getPath());
  63.     File[] listOfFiles = folder.listFiles();
  64.    
  65.     for (File file : listOfFiles) {
  66.        
  67.         if (file.isFile()) {
  68.             System.out.println(file.getCanonicalPath());
  69.             readers(file.getCanonicalPath());
  70.         }
  71.     }
  72. }  
  73.     public static void main(String[] args) {
  74.         SQLReader a = new SQLReader();
  75.        
  76.        
  77.         try{
  78.             a.getFile();}
  79.         catch(IOException e){
  80.             System.out.println("File Not Found");
  81.         }
  82.     }
  83.        
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement