public final class SQLUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static Object |
attribute2jdbcValue(Object value,
int sqlType)
Convert the attribute to expected jdbc type using java conversions.
|
static byte[] |
blob2ByteArray(Blob blobValue)
Make a blob conversion.
|
static void |
closeQuietly(Connection connection)
Deprecated.
@see
org.identityconnectors.common.IOUtil.quietClose(Statement); |
static void |
closeQuietly(DatabaseConnection conn)
Ignores any exception thrown by the
Connection parameter when
closed, it also checks for null. |
static void |
closeQuietly(ResultSet resultSet)
Deprecated.
@see
org.identityconnectors.common.IOUtil.quietClose(ResultSet); |
static void |
closeQuietly(Statement statement)
Deprecated.
@see
org.identityconnectors.common.IOUtil.quietClose(Statement); |
static String |
date2String(Date value)
Date to string.
|
static int |
executeUpdateStatement(Connection conn,
String sql,
SQLParam... params)
Executes DML sql statement.
|
static Map<String,SQLParam> |
getColumnValues(ResultSet resultSet)
Read one row from database result set and convert a columns to attribute
set.
|
static Connection |
getDatasourceConnection(String datasourceName)
Get the connection from the datasource.
|
static Connection |
getDatasourceConnection(String datasourceName,
Hashtable<?,?> env)
Get the connection from the datasource.
|
static Connection |
getDatasourceConnection(String datasourceName,
String user,
GuardedString password)
Get the connection from the dataSource with specified user and password.
|
static Connection |
getDatasourceConnection(String datasourceName,
String user,
GuardedString password,
Hashtable<?,?> env)
Get the connection from the dataSource with specified user and password.
|
static Connection |
getDriverMangerConnection(String driver,
String url,
Properties properties)
Gets a
Connection using the basic driver manager. |
static Connection |
getDriverMangerConnection(String driver,
String url,
String login,
GuardedString password)
Gets a
Connection using the basic driver manager. |
static Connection |
getDriverMangerConnection(String driver,
String url,
String login,
GuardedString password,
Properties properties)
Gets a
Connection using the basic driver manager. |
static Class<?> |
getSQLAttributeType(int sqlType)
Convert database type to connector supported set of attribute types Can
be redefined for different databases.
|
static SQLParam |
getSQLParam(ResultSet resultSet,
int i,
String name,
int sqlType)
Retrieve the SQL value from result set.
|
static Object |
jdbc2AttributeValue(Object value)
The conversion to required attribute type.
|
static String |
normalizeNullValues(String sql,
List<SQLParam> params,
List<SQLParam> out)
The null param value normalizer.
|
static void |
rollbackQuietly(Connection conn)
Ignores any exception thrown by the
Connection parameter when
closed, it also checks for null. |
static void |
rollbackQuietly(DatabaseConnection conn)
Ignores any exception thrown by the
DatabaseConnection parameter
when closed, it also checks for null. |
static List<Object[]> |
selectRows(Connection conn,
String sql,
SQLParam... params)
Selects all rows from select.
|
static Object |
selectSingleValue(Connection conn,
String sql,
SQLParam... params)
Selects single value (first column) from select.
|
static void |
setGuardedStringParam(PreparedStatement stmt,
int idx,
GuardedString guard)
The helper guardedString bind method.
|
static void |
setParams(CallableStatement statement,
List<SQLParam> params)
This method binds the "?"
|
static void |
setParams(PreparedStatement statement,
List<SQLParam> params)
This method binds the "?"
|
static void |
setSQLParam(PreparedStatement stmt,
int idx,
SQLParam parm)
Set a parameter to statement.
|
static Boolean |
string2Boolean(String val)
Convert String to boolean.
|
static Date |
string2Date(String param)
String to Date.
|
static Time |
string2Time(String param)
String to Time.
|
static Timestamp |
string2Timestamp(String param)
Convert string to Timestamp.
|
static String |
time2String(Time value)
Time to String format.
|
static String |
timestamp2String(Timestamp value)
Convert timestamp to string.
|
public static Connection getDatasourceConnection(String datasourceName, Hashtable<?,?> env)
datasourceName - env - propertyHastablepublic static Connection getDatasourceConnection(String datasourceName, String user, GuardedString password, Hashtable<?,?> env)
datasourceName - user - DB userpassword - DB passwordenv - propertyHastablepublic static Connection getDatasourceConnection(String datasourceName, String user, GuardedString password)
datasourceName - user - DB userpassword - DB passwordpublic static Connection getDatasourceConnection(String datasourceName)
datasourceName - public static Connection getDriverMangerConnection(String driver, String url, String login, GuardedString password)
Connection using the basic driver manager.driver - jdbc driver nameurl - jdbc connection urllogin - jdbc login namepassword - jdbc passwordpublic static Connection getDriverMangerConnection(String driver, String url, String login, GuardedString password, Properties properties)
Connection using the basic driver manager.driver - jdbc driver nameurl - jdbc connection urllogin - jdbc login namepassword - jdbc passwordproperties - a list of arbitrary string tag/value pairs as connection
argumentspublic static Connection getDriverMangerConnection(String driver, String url, Properties properties)
Connection using the basic driver manager.driver - jdbc driver nameurl - jdbc connection urlproperties - a list of arbitrary string tag/value pairs as connection
argumentspublic static void rollbackQuietly(Connection conn)
Connection parameter when
closed, it also checks for null.conn - JDBC connection to rollback.public static void rollbackQuietly(DatabaseConnection conn)
DatabaseConnection parameter
when closed, it also checks for null.conn - DatabaseConnection to rollback.public static void closeQuietly(Connection connection)
org.identityconnectors.common.IOUtil.quietClose(Statement);Connection parameter when
closed, it also checks for null.connection - JDBC connection to close.public static void closeQuietly(DatabaseConnection conn)
Connection parameter when
closed, it also checks for null.conn - DatabaseConnection to close.public static void closeQuietly(Statement statement)
org.identityconnectors.common.IOUtil.quietClose(Statement);Statement.close() method.statement - Statement to close.public static void closeQuietly(ResultSet resultSet)
org.identityconnectors.common.IOUtil.quietClose(ResultSet);resultSet - ResultSet to close quitely.public static String date2String(Date value)
value - Date valuepublic static String time2String(Time value)
value - Time valuepublic static String timestamp2String(Timestamp value)
value - Timestamppublic static Time string2Time(String param)
param - Stringpublic static Date string2Date(String param)
param - the String valuepublic static Timestamp string2Timestamp(String param)
param - String valuepublic static Boolean string2Boolean(String val)
val - string valuepublic static String normalizeNullValues(String sql, List<SQLParam> params, List<SQLParam> out)
sql - params - listout - out param listpublic static byte[] blob2ByteArray(Blob blobValue) throws SQLException
blobValue - blobSQLExceptionpublic static void setParams(PreparedStatement statement, List<SQLParam> params) throws SQLException
It concentrates the replacement of all params. GuardedString
are handled so the password is never visible.
statement - params - a List of the object argumentsSQLException - an exception in statementpublic static void setParams(CallableStatement statement, List<SQLParam> params) throws SQLException
It concentrates the replacement of all params. GuardedString
are handled so the password is never visible.
statement - params - a List of the object argumentsSQLException - an exception in statementpublic static Map<String,SQLParam> getColumnValues(ResultSet resultSet) throws SQLException
resultSet - database dataSQLExceptionpublic static SQLParam getSQLParam(ResultSet resultSet, int i, String name, int sqlType) throws SQLException
resultSet - the result seti - indexname - param namesqlType - expected SQL type or Types.NULL for genericSQLException - any SQL errorpublic static Class<?> getSQLAttributeType(int sqlType)
sqlType - #Typespublic static void setSQLParam(PreparedStatement stmt, int idx, SQLParam parm) throws SQLException
stmt - the statement to setidx - index of the parameterparm - the SQLParam valueSQLException - something wrongpublic static Object jdbc2AttributeValue(Object value) throws SQLException
value - to be converted to an attributeSQLException - something is not okpublic static Object attribute2jdbcValue(Object value, int sqlType) throws SQLException
value - the value to be convertedsqlType - the target sql typeSQLExceptionpublic static void setGuardedStringParam(PreparedStatement stmt, int idx, GuardedString guard) throws SQLException
stmt - to bind toidx - index of the objectguard - a GuardedString parameterSQLExceptionpublic static Object selectSingleValue(Connection conn, String sql, SQLParam... params) throws SQLException
conn - JDBC connectionsql - Select statement with or without parametersparams - Parameters to use in statementSQLExceptionpublic static List<Object[]> selectRows(Connection conn, String sql, SQLParam... params) throws SQLException
ResultSet.getMetaData() to find columns count and use
ResultSet.getObject(int) to retrieve column value.conn - JDBC connectionsql - SQL select with or without paramsparams - SQLExceptionpublic static int executeUpdateStatement(Connection conn, String sql, SQLParam... params) throws SQLException
conn - sql - params - PreparedStatement.executeUpdate()SQLExceptionCopyright © 2018–2025. All rights reserved.