Java SQL Execute executeQueries(Connection conn, InputStream stream)

Here you can find the source of executeQueries(Connection conn, InputStream stream)

Description

execute Queries

License

Open Source License

Declaration

public static void executeQueries(Connection conn, InputStream stream) throws IOException, SQLException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.sql.Connection;

import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    public static void executeQueries(Connection conn, InputStream stream) throws IOException, SQLException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));

        StringBuffer buf = new StringBuffer();
        String line;//from ww  w  .  j  a  v  a2s  . c o m

        while ((line = reader.readLine()) != null) {
            buf.append(line.trim());
        }

        String[] queries = buf.toString().split(";");
        Statement stmt = conn.createStatement();

        for (String query : queries) {
            stmt.execute(query);
        }

        conn.commit();
        stmt.close();
    }
}

Related

  1. executeDDL(String ddl)
  2. executeImmediate(String sql)
  3. executeInsert(Connection conn, String sql, boolean hasAutoGeneratedKey, Object... parameters)
  4. executeInsert(Connection conn, String targetTable, String destinationTable)
  5. executeInsertSQL(String sql)
  6. executeResource(Connection con, String resource)
  7. executeSetArgs(PreparedStatement stmt, Object... args)
  8. executeShutDownForHSQL(java.sql.Connection connection)
  9. executeSP(Connection conn, String spName, Object... parameters)