execute Batch Query from a File - Java java.sql

Java examples for java.sql:Statement

Description

execute Batch Query from a File

Demo Code


import java.sql.*;
import java.io.*;

public class Main{
    public static void executeBatchQuery(Connection con, String scriptFile) {
        Statement st;/*from ww w  .j  a  va 2  s.  co m*/
        BufferedReader br;
        String line;

        try {
            br = FileUtil.getTextReader(scriptFile);
            st = con.createStatement();
            while ((line = br.readLine()) != null) {
                System.out.println(line);
                st.executeUpdate(line);
            }
            System.out.println("Done!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials