public class SqlScriptRunner extends Object
| Modifier and Type | Field and Description |
|---|---|
static Pattern |
delimP
regex to detect delimiter.
|
| Constructor and Description |
|---|
SqlScriptRunner()
Default constructor
|
| Modifier and Type | Method and Description |
|---|---|
static QueryResult |
execCommand(Connection conn,
String command) |
static InsertionResultsDto |
execInsert(Connection conn,
List<InsertionDto> insertions,
InsertionResultsDto... previous)
Execute the different SQL insertions.
|
static Long |
execInsert(Connection conn,
String command)
Executes the given SQL insertion command.
|
static void |
execScript(Connection conn,
String script)
this is used for mysql which cannot execute multiple statements at one time.
|
static void |
execScript(Connection conn,
String script,
List<String> tablesToInsert) |
static List<String> |
extractSql(String script) |
static Map<String,List<String>> |
extractSqlTableMap(List<String> commands)
extract a map from table name to a list of SQL INSERT or Update commands for initializing data into the table
|
List<String> |
readCommands(Reader reader) |
String |
readSQLCommandsAsString(Reader reader) |
static void |
runCommands(Connection connection,
List<String> commands) |
static void |
runScript(Connection connection,
Reader reader)
Runs an SQL script (read in using the Reader parameter).
|
static void |
runScriptFromResourceFile(Connection connection,
String resourcePath) |
void |
setDelimiter(String delimiter,
boolean fullLineDelimiter) |
public static final Pattern delimP
public void setDelimiter(String delimiter, boolean fullLineDelimiter)
public static void runScript(Connection connection, Reader reader)
connection - the database connection to use for executing the scriptreader - the source of the scriptNullPointerException - if the reader is nullpublic static void runScriptFromResourceFile(Connection connection, String resourcePath)
public static void runCommands(Connection connection, List<String> commands)
public String readSQLCommandsAsString(Reader reader)
reader - for SQL scriptpublic static InsertionResultsDto execInsert(Connection conn, List<InsertionDto> insertions, InsertionResultsDto... previous) throws SQLException
conn - a JDBC connection to the databaseinsertions - the SQL insertions to executeprevious - the results of previously executed SQL insertionsSQLException - if a database access error occurspublic static Long execInsert(Connection conn, String command) throws SQLException
conn - a JDBC connection to the databasecommand - the SQL insertion to executenull otherwise.
In other words, returns the value of the auto-generated primary key, if any was created.SQLException - if a database access error occurspublic static void execScript(Connection conn, String script) throws SQLException
conn - a connection to dbscript - represents a sql scriptSQLException - if the execution of the command failspublic static void execScript(Connection conn, String script, List<String> tablesToInsert) throws SQLException
conn - a connection to dbscript - represents a sql scripttablesToInsert - represents insertions are executed only on the tables in this list.
insertions for other tables will be skipped.
if it is null or empty, nothing will be inserted.SQLException - if the execution of the command failspublic static List<String> extractSql(String script)
script - is a SQL scriptpublic static Map<String,List<String>> extractSqlTableMap(List<String> commands)
commands - a list of SQL commands to be extractedpublic static QueryResult execCommand(Connection conn, String command) throws SQLException
SQLExceptionCopyright © 2016–2025. All rights reserved.