public class JdbcUtil extends Object
Datadict table ALL_PROCEDURES contains all SP's in packages. The parameters for SPs can be glanced from ALL_ARGUMENTS; something odd so far is that doing a selection:
select * from sys.all_arguments where owner='DECADE' and package_name='GEBRUI' and object_name='LEES100';returns data that seem to indicate that the SP exists as a 2-parameter version but also an expanded version having all parameter fields.
| Modifier and Type | Field and Description |
|---|---|
static org.slf4j.Logger |
LOG |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
executeStatement(Connection dbc,
String sql,
Object... args) |
static boolean |
executeUpdatingCallableStatement(Connection dbc,
String sql,
Object... args)
Provides interface to execute SQL as
CallableStatement that is UPDATING DATA and also possibly return some values. |
static String |
hasChildRecords(Connection dbc,
String schemaName,
String tableName,
String primaryKey)
Check if the specified table's record (identified by schemaName, tableName and it's primary key) has child records.
|
static <T> T |
oracleSpCall(Connection con,
Class<T> rtype,
String sp,
Object... args)
Provides interface to call Oracle stored procedures and functions.
|
static boolean |
oracleSpCallReturningBool(Connection con,
String sp,
Object... args)
Similar as
oracleSpCall(Connection, Class, String, Object...),
adjusted to handle returning of oracle boolean type properly. |
static List<JdbcAnyRecord> |
queryAny(Connection dbc,
String select,
Object... parameters) |
static List<JdbcAnyRecord> |
queryAny(String tblname,
ResultSet rs) |
static JdbcAnyRecord |
queryAnyOne(Connection dbc,
String select,
Object... parameters) |
static JdbcAnyRecord |
queryAnyOne(String tblname,
ResultSet rs) |
static Date |
readDate(ResultSet rs,
String colName) |
static Integer |
readInt(ResultSet rs,
String colName) |
static Long |
readLong(ResultSet rs,
String colName) |
static void |
readParameters(PreparedStatement ps,
int startindex,
Object[] params) |
static Date |
readTimestamp(ResultSet rs,
int colIndex) |
static <T> T |
selectOne(Connection connection,
Class<T> clz,
String select,
Object... params)
Quick method to select a single value of a given type from the database.
|
static <T> List<T> |
selectSingleColumnList(Connection connection,
Class<T> clz,
String select,
Object... params)
Quick method to select a single value of a given type from the database.
|
static void |
setDateTruncated(PreparedStatement ps,
int index,
Date value)
Sets a truncated date containing only the date part and a zero time.
|
static void |
setDouble(PreparedStatement ps,
int index,
Double value) |
static void |
setFK(PreparedStatement ps,
int index,
IIdentifyable<? extends Number> foreigner) |
static void |
setInteger(PreparedStatement ps,
int index,
Integer value) |
static void |
setLong(PreparedStatement ps,
int index,
Long value) |
static void |
setParameter(PreparedStatement ps,
Object val,
int px) |
static void |
setParameters(PreparedStatement ps,
int startindex,
Object[] params) |
static void |
setString(PreparedStatement ps,
int index,
String value) |
static void |
setStringTruncated(PreparedStatement ps,
int index,
String value,
int maxlen) |
static void |
setTimestamp(PreparedStatement ps,
int index,
Date value)
Sets a TIMESTAMP value containing both TIME and DATE values.
|
static void |
setYN(PreparedStatement ps,
int index,
Boolean value) |
public static void setLong(@Nonnull PreparedStatement ps, int index, Long value) throws SQLException
SQLExceptionpublic static void setInteger(@Nonnull PreparedStatement ps, int index, Integer value) throws SQLException
SQLExceptionpublic static void setDouble(@Nonnull PreparedStatement ps, int index, Double value) throws SQLException
SQLExceptionpublic static void setTimestamp(@Nonnull PreparedStatement ps, int index, Date value) throws SQLException
ps - index - value - SQLExceptionpublic static void setDateTruncated(@Nonnull PreparedStatement ps, int index, Date value) throws SQLException
ps - index - value - SQLExceptionpublic static void setString(@Nonnull PreparedStatement ps, int index, String value) throws SQLException
SQLExceptionpublic static void setStringTruncated(@Nonnull PreparedStatement ps, int index, String value, int maxlen) throws SQLException
SQLExceptionpublic static void setYN(@Nonnull PreparedStatement ps, int index, Boolean value) throws SQLException
SQLExceptionpublic static void setFK(@Nonnull PreparedStatement ps, int index, @Nullable IIdentifyable<? extends Number> foreigner) throws SQLException
SQLExceptionpublic static <T> T selectOne(@Nonnull Connection connection, @Nonnull Class<T> clz, @Nonnull String select, @Nonnull Object... params) throws SQLException
connection - clz - select - SQLExceptionpublic static <T> List<T> selectSingleColumnList(@Nonnull Connection connection, @Nonnull Class<T> clz, @Nonnull String select, @Nonnull Object... params) throws SQLException
connection - clz - select - SQLExceptionpublic static void setParameters(@Nonnull PreparedStatement ps, int startindex, @Nullable Object[] params) throws SQLException
SQLExceptionpublic static void setParameter(@Nonnull PreparedStatement ps, @Nullable Object val, int px) throws SQLException
SQLExceptionpublic static void readParameters(@Nonnull PreparedStatement ps, int startindex, @Nullable Object[] params) throws SQLException
SQLExceptionpublic static List<JdbcAnyRecord> queryAny(@Nonnull Connection dbc, @Nonnull String select, Object... parameters) throws SQLException
SQLExceptionpublic static List<JdbcAnyRecord> queryAny(String tblname, ResultSet rs) throws SQLException
SQLExceptionpublic static JdbcAnyRecord queryAnyOne(@Nonnull Connection dbc, @Nonnull String select, Object... parameters) throws SQLException
SQLExceptionpublic static JdbcAnyRecord queryAnyOne(@Nonnull String tblname, @Nonnull ResultSet rs) throws SQLException
SQLExceptionpublic static boolean executeStatement(@Nonnull Connection dbc, @Nonnull String sql, Object... args) throws SQLException
SQLExceptionpublic static boolean executeUpdatingCallableStatement(@Nonnull Connection dbc, @Nonnull String sql, @Nullable Object... args) throws SQLException
CallableStatement that is UPDATING DATA and also possibly return some values.
Out values should be specified as JdbcOutParam.
In case that intention is to just execute CallableStatement that does not explicitly do updates (i.e. to execute stored procedure), please use
executeStatement(java.sql.Connection, java.lang.String, java.lang.Object...) or oracleSpCall(java.sql.Connection, java.lang.Class<T>, java.lang.String, java.lang.Object...) methods.dbc - sql - i.e. "begin insert into table1(colA, colB, colC) values (?,?,?) returning colId into ? ; end;"args - SQLExceptionpublic static <T> T oracleSpCall(@Nonnull Connection con, @Nonnull Class<T> rtype, @Nonnull String sp, @Nonnull Object... args) throws SQLException
oracleSpCallReturningBool(Connection, String, Object...)
Support all three type of parameters:JdbcOutParamJdbcInOutParamT - Oracle function return value typecon - Db connectionrtype - Oracle function return typesp - Stored procedure / function nameargs - Stored procedure / function parametersSQLExceptionpublic static boolean oracleSpCallReturningBool(@Nonnull Connection con, @Nonnull String sp, @Nonnull Object... args) throws SQLException
oracleSpCall(Connection, Class, String, Object...),
adjusted to handle returning of oracle boolean type properly.con - sp - args - For hanlding IN/OUT/IN OUT params see oracleSpCall(Connection, Class, String, Object...)SQLException@Nullable public static String hasChildRecords(@Nonnull Connection dbc, @Nullable String schemaName, @Nonnull String tableName, @Nonnull String primaryKey) throws Exception
This method is only suitable for relations without compound keys, and the key's value must be representable and convertible by JDBC to and from String. The method takes care of cascading, allowing a delete if child records are present with delete-cascade rule, and it checks if those delete-cascaded records are deleteable themselves recursively.
dbc - schemaName - tableName - primaryKey - Exception@Nullable public static Long readLong(@Nonnull ResultSet rs, @Nonnull String colName) throws SQLException
SQLException@Nullable public static Integer readInt(@Nonnull ResultSet rs, @Nonnull String colName) throws SQLException
SQLException@Nullable public static Date readDate(@Nonnull ResultSet rs, @Nonnull String colName) throws SQLException
SQLException@Nullable public static Date readTimestamp(@Nonnull ResultSet rs, int colIndex) throws SQLException
SQLExceptionCopyright © 2017 etc.to. All rights reserved.