public class SQLUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
SQLUtils.CompareMode
Specifies how two SQL terms should be compared
|
static class |
SQLUtils.WhereClause<V> |
static class |
SQLUtils.WhereClauseBuilder<V> |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_SQLITE_DATABASE |
static java.lang.String |
MYSQL |
static java.lang.String |
ORACLE |
static java.lang.String |
POSTGRESQL |
static java.lang.String |
SQLITE |
static java.lang.String |
SQLSERVER |
static char |
WILDCARD_ESCAPE
The escape character (backslash) used by convertWildcards() and getLikeEscapeClause()
|
Constructor and Description |
---|
SQLUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addColumn(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.lang.String columnName,
java.lang.String columnType) |
static void |
addForeignKey(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.lang.String keyName,
java.lang.String targetTable,
java.lang.String targetKey) |
static java.lang.String |
binarySQLType(java.lang.String dbms)
This function returns the name of a binary data type that can be used in SQL queries.
|
static java.lang.String |
caseSensitiveCompare(java.sql.Connection conn,
java.lang.String expr1,
java.lang.String expr2)
This will build a case sensitive compare expression out of two sql query expressions.
|
static void |
cleanup(java.sql.Connection obj) |
static void |
cleanup(java.sql.ResultSet obj) |
static void |
cleanup(java.sql.Statement obj) |
static boolean |
connectionIsValid(java.sql.Connection conn)
This function tests if a given Connection is valid, and closes the connection if it is not.
|
protected static <T> T |
constrainOracleQueryParam(T param) |
protected static <T> void |
constrainQueryParams(java.sql.Connection conn,
java.util.List<T> params) |
protected static <T> void |
constrainQueryParams(java.sql.Connection conn,
T[] params) |
static java.lang.String |
convertWildcards(java.lang.String searchString)
Converts a search string which uses basic '?' and '*' wildcards into an equivalent SQL search string.
|
static void |
createIndex(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.lang.String[] columnNames) |
static void |
createIndex(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.lang.String[] columnNames,
java.lang.Integer[] columnLengths) |
static void |
createSchema(java.sql.Connection conn,
java.lang.String schema)
Creates a schema in a non-SQLite database.
|
static void |
createTable(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.util.List<java.lang.String> columnNames,
java.util.List<java.lang.String> columnTypes,
java.util.List<java.lang.String> primaryKeyColumns) |
static <V> int |
deleteRows(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
SQLUtils.WhereClause<V> where)
This function will delete from a table the rows that have a specified set of column values.
|
static void |
dropTableIfExists(java.sql.Connection conn,
java.lang.String schema,
java.lang.String table) |
static int |
executeUpdate(java.sql.Connection connection,
java.lang.String query) |
static int |
executeUpdate(java.sql.Connection conn,
java.lang.String query,
java.lang.Object[] params) |
static java.lang.String |
fixColumnName(java.lang.String colName,
java.lang.String suffix) |
static java.lang.String |
getBigIntTypeString(java.sql.Connection conn) |
static java.util.List<java.lang.String> |
getColumn(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.lang.String columnArg) |
static java.lang.String[] |
getColumnNamesFromResultSet(java.sql.ResultSet rs) |
static java.util.List<java.lang.String> |
getColumns(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName) |
static java.sql.Connection |
getConnection(java.lang.String connectString) |
static java.sql.Connection |
getConnection(java.lang.String connectString,
java.lang.String user,
java.lang.String pass) |
static java.lang.String |
getConnectString(java.lang.String dbms,
java.lang.String ip,
java.lang.String port,
java.lang.String database,
java.lang.String user,
java.lang.String pass) |
protected static java.lang.String |
getCSVNullValue(java.sql.Connection conn) |
static java.lang.String |
getDateTimeTypeString(java.sql.Connection conn) |
static java.lang.String |
getDbmsFromConnection(java.sql.Connection conn) |
static java.lang.String |
getDbmsFromConnectString(java.lang.String connectString) |
static java.lang.String |
getDoubleTypeString(java.sql.Connection conn) |
static java.lang.String |
getDriver(java.lang.String dbms) |
static java.util.List<java.lang.Integer> |
getIntColumn(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.lang.String columnArg) |
static java.lang.String |
getIntTypeString(java.sql.Connection conn) |
static java.lang.String |
getLikeEscapeClause(java.sql.Connection conn)
Returns an ESCAPE clause for use with a LIKE comparison.
|
static java.lang.String |
getLongBlobTypeString(java.sql.Connection conn) |
static <VALUE_TYPE> |
getRecordsFromQuery(java.sql.Connection conn,
java.util.List<java.lang.String> selectColumns,
java.lang.String fromSchema,
java.lang.String fromTable,
SQLUtils.WhereClause<VALUE_TYPE> where,
java.lang.String orderBy,
java.lang.Class<VALUE_TYPE> valueType) |
static <VALUE_TYPE> |
getRecordsFromResultSet(java.sql.ResultSet rs,
java.lang.Class<VALUE_TYPE> valueType) |
static <V> SQLResult |
getResultFromQuery(java.sql.Connection conn,
java.util.List<java.lang.String> selectColumns,
java.lang.String fromSchema,
java.lang.String fromTable,
java.util.Map<java.lang.String,V> whereParams,
java.util.Set<java.lang.String> caseSensitiveFields) |
static <TYPE> SQLResult |
getResultFromQuery(java.sql.Connection connection,
java.lang.String query,
TYPE[] params,
boolean convertToStrings)
Example usage:
getResultFromQuery(conn, "SELECT a, b FROM mytable WHERE c = ? and d = ?", new Object[]| "my-c-value", 0xDDDD }, false)
|
static java.util.List<java.lang.String> |
getSchemas(java.sql.Connection conn) |
static int |
getSingleIntFromQuery(java.sql.Connection conn,
java.lang.String query,
int defaultValue) |
static int |
getSingleIntFromQuery(java.sql.Connection conn,
java.lang.String query,
java.lang.Object[] params,
int defaultValue) |
static int |
getSingleIntFromQuery(java.sql.Statement stmt,
java.lang.String query,
int defaultValue) |
static java.sql.Connection |
getStaticReadOnlyConnection(java.lang.String connectString,
java.lang.String user,
java.lang.String pass)
This function returns a read-only connection that can be reused.
|
static java.util.List<java.lang.String> |
getTables(java.sql.Connection conn,
java.lang.String schemaName) |
static java.lang.String |
getTinyIntTypeString(java.sql.Connection conn) |
static java.lang.String |
getVarcharTypeString(java.sql.Connection conn,
int length) |
static <V> int |
insertRow(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.util.Map<java.lang.String,V> record) |
static int |
insertRowReturnID(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.util.Map<java.lang.String,java.lang.Object> data,
java.lang.String idField)
Generates a new id manually using MAX(idField)+1.
|
static <V> int |
insertRows(java.sql.Connection conn,
java.lang.String schemaName,
java.lang.String tableName,
java.util.List<java.util.Map<java.lang.String,V>> records) |
static boolean |
isMySQL(java.sql.Connection conn)
This function checks if a connection is for a MySQL server.
|
static boolean |
isOracleServer(java.sql.Connection conn)
This function checks if a connection is for an Oracle server.
|
static boolean |
isPostgreSQL(java.sql.Connection conn)
This function checks if a connection is for a PostgreSQL server.
|
static boolean |
isSQLite(java.sql.Connection conn)
This function checks if a connection is for a SQLite server.
|
static boolean |
isSQLServer(java.sql.Connection conn)
This function checks if a connection is for a Microsoft SQL Server.
|
static <TYPE> java.sql.PreparedStatement |
prepareStatement(java.sql.Connection conn,
java.lang.String query,
java.util.List<TYPE> params) |
static <TYPE> java.sql.PreparedStatement |
prepareStatement(java.sql.Connection conn,
java.lang.String query,
TYPE[] params) |
static java.lang.String |
quoteSchemaTable(java.sql.Connection conn,
java.lang.String schema,
java.lang.String table)
Returns quoted schema & table to use in SQL queries for the given Connection.
|
static java.lang.String |
quoteSchemaTable(java.lang.String dbms,
java.lang.String schema,
java.lang.String table)
Returns quoted schema & table to use in SQL queries for the given DBMS.
|
static java.lang.String |
quoteSymbol(java.sql.Connection conn,
java.lang.String symbol) |
static java.lang.String |
quoteSymbol(java.lang.String dbms,
java.lang.String symbol) |
static boolean |
schemaExists(java.sql.Connection conn,
java.lang.String schema) |
static <TYPE> void |
setPreparedStatementParams(java.sql.PreparedStatement cstmt,
java.util.List<TYPE> params) |
static <TYPE> void |
setPreparedStatementParams(java.sql.PreparedStatement cstmt,
TYPE[] params) |
static void |
setSQLServerIdentityInsert(java.sql.Connection conn,
java.lang.String schema,
java.lang.String table,
boolean on)
This function should only be called on a SQL Server connection.
|
static boolean |
sqlTypeIsGeometry(int sqlType) |
static boolean |
sqlTypeIsNumeric(int sqlType) |
static void |
staticCleanup()
Call this when shutting down your application to deregister SQL drivers.
|
static java.lang.String |
stringCast(java.sql.Connection conn,
java.lang.String queryExpression)
This will wrap a query expression in a string cast.
|
static boolean |
tableExists(java.sql.Connection conn,
java.lang.String schema,
java.lang.String table) |
static void |
testConnection(java.sql.Connection conn)
This function will test a connection by running a simple test query.
|
static java.lang.String |
unquoteSymbol(java.sql.Connection conn,
java.lang.String symbol) |
static java.lang.String |
unquoteSymbol(java.lang.String dbms,
java.lang.String symbol) |
static int |
updateRows(java.sql.Connection conn,
java.lang.String fromSchema,
java.lang.String fromTable,
java.util.Map<java.lang.String,java.lang.Object> whereParams,
java.util.Map<java.lang.String,java.lang.Object> dataUpdate,
java.util.Set<java.lang.String> caseSensitiveFields) |
public static java.lang.String MYSQL
public static java.lang.String SQLITE
public static java.lang.String POSTGRESQL
public static java.lang.String SQLSERVER
public static java.lang.String ORACLE
public static java.lang.String DEFAULT_SQLITE_DATABASE
public static final char WILDCARD_ESCAPE
public static java.lang.String getDriver(java.lang.String dbms) throws java.rmi.RemoteException
dbms
- The name of a DBMS (MySQL, PostgreSQL, ...)java.rmi.RemoteException
public static java.lang.String getDbmsFromConnection(java.sql.Connection conn)
public static java.lang.String getDbmsFromConnectString(java.lang.String connectString) throws java.rmi.RemoteException
java.rmi.RemoteException
public static java.lang.String getConnectString(java.lang.String dbms, java.lang.String ip, java.lang.String port, java.lang.String database, java.lang.String user, java.lang.String pass)
dbms
- The name of a DBMS (MySQL, PostgreSQL, Microsoft SQL Server)ip
- The IP address of the DBMS.port
- The port the DBMS is on (optional, can be "" to use default).database
- The name of a database to connect to (can be "" for MySQL)user
- The username to use when connecting.pass
- The password associated with the username.public static void staticCleanup()
public static void testConnection(java.sql.Connection conn) throws java.sql.SQLException
conn
- A SQL Connection.java.sql.SQLException
- Thrown if the test query fails.public static boolean connectionIsValid(java.sql.Connection conn)
conn
- A Connection object which may or may not be valid.public static java.sql.Connection getStaticReadOnlyConnection(java.lang.String connectString, java.lang.String user, java.lang.String pass) throws java.rmi.RemoteException
connectString
- The connect string used to create the Connection.java.rmi.RemoteException
public static java.sql.Connection getConnection(java.lang.String connectString) throws java.rmi.RemoteException
connectString
- The connect string to use.java.rmi.RemoteException
public static java.sql.Connection getConnection(java.lang.String connectString, java.lang.String user, java.lang.String pass) throws java.rmi.RemoteException
connectString
- The connect string to use.user
- The user namepass
- The passwordjava.rmi.RemoteException
public static java.lang.String fixColumnName(java.lang.String colName, java.lang.String suffix)
colName
- public static java.lang.String quoteSymbol(java.lang.String dbms, java.lang.String symbol) throws java.lang.IllegalArgumentException
dbms
- The name of a DBMS (MySQL, PostgreSQL, ...)symbol
- The symbol to quote.java.lang.IllegalArgumentException
public static java.lang.String quoteSymbol(java.sql.Connection conn, java.lang.String symbol) throws java.sql.SQLException, java.lang.IllegalArgumentException
conn
- An SQL connection.symbol
- The symbol to quote.java.sql.SQLException
java.lang.IllegalArgumentException
public static java.lang.String unquoteSymbol(java.lang.String dbms, java.lang.String symbol)
dbms
- The name of a DBMS (MySQL, PostgreSQL, ...)symbol
- The quoted symbol.public static java.lang.String unquoteSymbol(java.sql.Connection conn, java.lang.String symbol) throws java.sql.SQLException, java.lang.IllegalArgumentException
conn
- An SQL connection.symbol
- The quoted symbol.java.sql.SQLException
java.lang.IllegalArgumentException
public static java.lang.String caseSensitiveCompare(java.sql.Connection conn, java.lang.String expr1, java.lang.String expr2) throws java.sql.SQLException
conn
- An SQL Connection.expr1
- The first SQL expression to be used in the comparison.expr2
- The second SQL expression to be used in the comparison.java.sql.SQLException
public static java.lang.String stringCast(java.sql.Connection conn, java.lang.String queryExpression) throws java.sql.SQLException
conn
- An SQL Connection.queryExpression
- An expression to be used in a SQL Query.java.sql.SQLException
public static java.lang.String binarySQLType(java.lang.String dbms)
dbms
- The name of a DBMS (MySQL, PostgreSQL, ...)public static java.lang.String quoteSchemaTable(java.lang.String dbms, java.lang.String schema, java.lang.String table)
dbms
- The name of a DBMS (MySQL, PostgreSQL, ...)schema
- The schema the table resides in.table
- The table.public static java.lang.String quoteSchemaTable(java.sql.Connection conn, java.lang.String schema, java.lang.String table) throws java.sql.SQLException
conn
- An SQL connection.schema
- The schema the table resides in.table
- The table.java.sql.SQLException
public static boolean sqlTypeIsNumeric(int sqlType)
public static boolean sqlTypeIsGeometry(int sqlType)
public static <TYPE> SQLResult getResultFromQuery(java.sql.Connection connection, java.lang.String query, TYPE[] params, boolean convertToStrings) throws java.sql.SQLException
getResultFromQuery(conn, "SELECT a, b FROM mytable WHERE c = ? and d = ?", new Object[]| "my-c-value", 0xDDDD }, false)
connection
- An SQL Connectionquery
- An SQL Query with '?' place holders for parametersparams
- Parameters for the SQL query for all '?' place holders, or null if there are no parameters.java.sql.SQLException
public static <VALUE_TYPE> java.util.List<java.util.Map<java.lang.String,VALUE_TYPE>> getRecordsFromResultSet(java.sql.ResultSet rs, java.lang.Class<VALUE_TYPE> valueType) throws java.sql.SQLException
rs
- The ResultSet returned from a SQL query.valueType
- The Class used for casting values in the ResultSet.java.sql.SQLException
- If the query fails.public static java.lang.String[] getColumnNamesFromResultSet(java.sql.ResultSet rs) throws java.sql.SQLException
java.sql.SQLException
public static <VALUE_TYPE> java.util.List<java.util.Map<java.lang.String,VALUE_TYPE>> getRecordsFromQuery(java.sql.Connection conn, java.util.List<java.lang.String> selectColumns, java.lang.String fromSchema, java.lang.String fromTable, SQLUtils.WhereClause<VALUE_TYPE> where, java.lang.String orderBy, java.lang.Class<VALUE_TYPE> valueType) throws java.sql.SQLException
conn
- An existing SQL ConnectionselectColumns
- The list of column names, or null for all columnsfromSchema
- The schema containing the table to perform the SELECT statement on.fromTable
- The table to perform the SELECT statement on.where
- Used to construct the WHERE clauseorderBy
- The field to order by, or null for no specific order.valueType
- Either String.class or Object.class to denote the VALUE_TYPE class.java.sql.SQLException
- If the query fails.public static <V> SQLResult getResultFromQuery(java.sql.Connection conn, java.util.List<java.lang.String> selectColumns, java.lang.String fromSchema, java.lang.String fromTable, java.util.Map<java.lang.String,V> whereParams, java.util.Set<java.lang.String> caseSensitiveFields) throws java.sql.SQLException
conn
- An existing SQL ConnectionselectColumns
- The list of columns in the SELECT statement, or null for all columns.fromSchema
- The schema containing the table to perform the SELECT statement on.fromTable
- The table to perform the SELECT statement on.whereParams
- A map of column names to String values used to construct a WHERE clause.java.sql.SQLException
- If the query fails.public static int executeUpdate(java.sql.Connection connection, java.lang.String query) throws java.sql.SQLException
java.sql.SQLException
public static int executeUpdate(java.sql.Connection conn, java.lang.String query, java.lang.Object[] params) throws java.sql.SQLException
java.sql.SQLException
public static int getSingleIntFromQuery(java.sql.Connection conn, java.lang.String query, int defaultValue) throws java.sql.SQLException
java.sql.SQLException
public static int getSingleIntFromQuery(java.sql.Statement stmt, java.lang.String query, int defaultValue) throws java.sql.SQLException
java.sql.SQLException
public static int getSingleIntFromQuery(java.sql.Connection conn, java.lang.String query, java.lang.Object[] params, int defaultValue) throws java.sql.SQLException
java.sql.SQLException
public static java.util.List<java.lang.String> getSchemas(java.sql.Connection conn) throws java.sql.SQLException
conn
- An existing SQL Connectionjava.sql.SQLException
- If the query fails.public static java.util.List<java.lang.String> getTables(java.sql.Connection conn, java.lang.String schemaName) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectionjava.sql.SQLException
- If the query fails.public static java.util.List<java.lang.String> getColumns(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- A table name existing in the given schemajava.sql.SQLException
- If the query fails.public static void createSchema(java.sql.Connection conn, java.lang.String schema) throws java.sql.SQLException
conn
- An existing SQL Connectionschema
- The value to be used as the Schema namejava.sql.SQLException
- If the query fails.public static void createTable(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.util.List<java.lang.String> columnNames, java.util.List<java.lang.String> columnTypes, java.util.List<java.lang.String> primaryKeyColumns) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- The value to be used as the table namecolumnNames
- The values to be used as the column namescolumnTypes
- The SQL types to use when creating the tableprimaryKeyColumns
- The list of columns to be used for primary keysjava.sql.SQLException
- If the query fails.public static void addForeignKey(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.lang.String keyName, java.lang.String targetTable, java.lang.String targetKey) throws java.sql.SQLException
java.sql.SQLException
public static <TYPE> java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, java.lang.String query, java.util.List<TYPE> params) throws java.sql.SQLException
java.sql.SQLException
public static <TYPE> java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, java.lang.String query, TYPE[] params) throws java.sql.SQLException
java.sql.SQLException
protected static <T> void constrainQueryParams(java.sql.Connection conn, java.util.List<T> params)
protected static <T> void constrainQueryParams(java.sql.Connection conn, T[] params)
protected static <T> T constrainOracleQueryParam(T param)
public static <TYPE> void setPreparedStatementParams(java.sql.PreparedStatement cstmt, java.util.List<TYPE> params) throws java.sql.SQLException
java.sql.SQLException
public static <TYPE> void setPreparedStatementParams(java.sql.PreparedStatement cstmt, TYPE[] params) throws java.sql.SQLException
java.sql.SQLException
public static int updateRows(java.sql.Connection conn, java.lang.String fromSchema, java.lang.String fromTable, java.util.Map<java.lang.String,java.lang.Object> whereParams, java.util.Map<java.lang.String,java.lang.Object> dataUpdate, java.util.Set<java.lang.String> caseSensitiveFields) throws java.sql.SQLException
java.sql.SQLException
public static int insertRowReturnID(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.util.Map<java.lang.String,java.lang.Object> data, java.lang.String idField) throws java.sql.SQLException
conn
- schemaName
- tableName
- data
- Unquoted field names mapped to raw values.idField
- java.sql.SQLException
public static boolean isPostgreSQL(java.sql.Connection conn)
conn
- A SQL Connection.java.sql.SQLException
public static boolean isMySQL(java.sql.Connection conn)
conn
- A SQL Connection.java.sql.SQLException
public static boolean isOracleServer(java.sql.Connection conn)
conn
- A SQL Connection.java.sql.SQLException
public static boolean isSQLServer(java.sql.Connection conn)
conn
- A SQL Connection.public static boolean isSQLite(java.sql.Connection conn)
conn
- A SQL Connection.public static void createIndex(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.lang.String[] columnNames) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- The name of an existing tablecolumnNames
- The names of the columns to usejava.sql.SQLException
- If the query fails.public static void createIndex(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.lang.String[] columnNames, java.lang.Integer[] columnLengths) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- The name of an existing tablecolumnNames
- The names of the columns to use.columnLengths
- The lengths to use as indices, may be null.java.sql.SQLException
- If the query fails.public static void addColumn(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.lang.String columnName, java.lang.String columnType) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- The name of an existing tablecolumnName
- The name of the column to createcolumnType
- An SQL type to use when creating the columnjava.sql.SQLException
- If the query fails.public static java.util.List<java.lang.String> getColumn(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.lang.String columnArg) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- A table name existing in the given schemacolumnArg
- The name of the column to grabjava.sql.SQLException
- If the query fails.public static java.util.List<java.lang.Integer> getIntColumn(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.lang.String columnArg) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- A table name existing in the given schemacolumnArg
- The name of the integer column to grabjava.sql.SQLException
- If the query fails.public static <V> int insertRow(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.util.Map<java.lang.String,V> record) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- A table name existing in the given schemarecord
- The record to be inserted into the tablejava.sql.SQLException
- If the query fails.public static <V> int insertRows(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, java.util.List<java.util.Map<java.lang.String,V>> records) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- A table name existing in the given schemarecords
- The records to be inserted into the tablejava.sql.SQLException
- If the query fails.public static boolean schemaExists(java.sql.Connection conn, java.lang.String schema) throws java.sql.SQLException
conn
- An existing SQL Connectionschema
- The name of a schema to check for.java.sql.SQLException
- If the getSchemas query fails.public static void dropTableIfExists(java.sql.Connection conn, java.lang.String schema, java.lang.String table) throws java.sql.SQLException
java.sql.SQLException
public static <V> int deleteRows(java.sql.Connection conn, java.lang.String schemaName, java.lang.String tableName, SQLUtils.WhereClause<V> where) throws java.sql.SQLException
conn
- An existing SQL ConnectionschemaName
- A schema name accessible through the given connectiontableName
- A table name existing in the given schemawhere
- The conditions to be used in the WHERE clause of the queryjava.sql.SQLException
- If the query fails.public static boolean tableExists(java.sql.Connection conn, java.lang.String schema, java.lang.String table) throws java.sql.SQLException
conn
- An existing SQL Connectionschema
- The name of a schema to check in.table
- The name of a table to check for.java.sql.SQLException
- If either getSchemas() or getTables() fails.public static void cleanup(java.sql.ResultSet obj)
public static void cleanup(java.sql.Statement obj)
public static void cleanup(java.sql.Connection obj)
public static java.lang.String getVarcharTypeString(java.sql.Connection conn, int length)
public static java.lang.String getTinyIntTypeString(java.sql.Connection conn) throws java.sql.SQLException
java.sql.SQLException
public static java.lang.String getIntTypeString(java.sql.Connection conn)
public static java.lang.String getDoubleTypeString(java.sql.Connection conn)
public static java.lang.String getBigIntTypeString(java.sql.Connection conn)
public static java.lang.String getDateTimeTypeString(java.sql.Connection conn)
public static java.lang.String getLongBlobTypeString(java.sql.Connection conn)
protected static java.lang.String getCSVNullValue(java.sql.Connection conn)
public static void setSQLServerIdentityInsert(java.sql.Connection conn, java.lang.String schema, java.lang.String table, boolean on) throws java.sql.SQLException
conn
- schema
- table
- on
- java.sql.SQLException
public static java.lang.String convertWildcards(java.lang.String searchString)
searchString
- A search string which uses basic '?' and '*' wildcardsgetLikeEscapeClause(Connection)
public static java.lang.String getLikeEscapeClause(java.sql.Connection conn)
conn
- The SQL Connection where the ESCAPE clause will be used.convertWildcards(String)