Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sqlreader;
- import com.csvreader.CsvReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- /**
- *
- * @author NasiPadang
- */
- public class SQLReader {
- private String value;
- private String SQL;
- void readers(String filepath){
- try{
- File file = new File(filepath);
- System.out.println(filepath);
- System.out.println(file.getCanonicalPath());
- CsvReader reader= new CsvReader(filepath);
- System.out.println(reader.getColumnCount());
- value="";
- reader.readHeaders();
- /*
- Insert your database name and consider the SQL Syntax
- */
- while(reader.readRecord()){
- value ="INSERT INTO ALL_ROW_REPORT_2013 VALUES(";
- for(int i=0;i<17;i++){
- value = value + "'" +reader.get(i)+"',";
- if(i==16)
- value = value +"'"+reader.get(i)+"');";
- }
- //SQL = ""+value+")";
- System.out.println(value);
- ReaderDAO b = new ReaderDAO();
- try{
- b.connection(value);
- System.out.println("Insert Successfull");}
- catch(Exception e){
- System.out.println(e);}
- }
- }
- catch(FileNotFoundException e){
- System.out.println("File Not Found");
- System.out.println(e.getMessage());
- }
- catch(IOException ea){
- System.out.println(ea.getMessage());
- System.out.println("File Not Exist");
- }
- }
- /*
- Place your directory here
- */
- void getFile() throws IOException{
- File folder = new File("C:\\Dir\\");
- System.out.println(folder.getPath());
- File[] listOfFiles = folder.listFiles();
- for (File file : listOfFiles) {
- if (file.isFile()) {
- System.out.println(file.getCanonicalPath());
- readers(file.getCanonicalPath());
- }
- }
- }
- public static void main(String[] args) {
- SQLReader a = new SQLReader();
- try{
- a.getFile();}
- catch(IOException e){
- System.out.println("File Not Found");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement