@@ -20,15 +20,11 @@ private DBHelper() {}
2020 * @throws SQLException any database error
2121 */
2222 public static String newSysGuid (Connection conn ) throws SQLException {
23- CallableStatement callableStatement = null ;
24- try {
25- callableStatement = conn .prepareCall ("BEGIN ? := sys_guid(); END;" );
23+ assert conn != null ;
24+ try (CallableStatement callableStatement = conn .prepareCall ("BEGIN ? := sys_guid(); END;" )) {
2625 callableStatement .registerOutParameter (1 , OracleTypes .RAW );
2726 callableStatement .executeUpdate ();
2827 return callableStatement .getString (1 );
29- } finally {
30- if (callableStatement != null )
31- callableStatement .close ();
3228 }
3329 }
3430
@@ -39,26 +35,22 @@ public static String newSysGuid(Connection conn) throws SQLException {
3935 * @throws SQLException any database error
4036 */
4137 public static String getCurrentSchema (Connection conn ) throws SQLException {
42- CallableStatement callableStatement = null ;
43- try {
44- callableStatement = conn .prepareCall ("BEGIN ? := sys_context('userenv', 'current_schema'); END;" );
38+ assert conn != null ;
39+ try (CallableStatement callableStatement = conn .prepareCall ("BEGIN ? := sys_context('userenv', 'current_schema'); END;" )) {
4540 callableStatement .registerOutParameter (1 , Types .VARCHAR );
4641 callableStatement .executeUpdate ();
4742 return callableStatement .getString (1 );
48- } finally {
49- if (callableStatement != null )
50- callableStatement .close ();
5143 }
5244 }
5345
5446 /** Returns the Frameworks version string of the given connection
5547 *
5648 * @param conn Active db connection
57- * @return
58- * @throws SQLException
49+ * @return Version-string of the utPLSQL framework
50+ * @throws SQLException any database error
5951 */
60- public static Version getDatabaseFrameworkVersion ( Connection conn )
61- throws SQLException {
52+ public static Version getDatabaseFrameworkVersion ( Connection conn ) throws SQLException {
53+ assert conn != null ;
6254 Version result = new Version ("" );
6355 try (PreparedStatement stmt = conn .prepareStatement ("select ut_runner.version() from dual" ))
6456 {
@@ -78,11 +70,32 @@ public static Version getDatabaseFrameworkVersion( Connection conn )
7870 return result ;
7971 }
8072
73+ /** Returns the Oracle database Version from a given connection object
74+ *
75+ * @param conn Connection-Object
76+ * @return Returns version-string of the Oracle Database product component
77+ * @throws SQLException any database error
78+ */
79+ public static String getOracleDatabaseVersion ( Connection conn ) throws SQLException {
80+ assert conn != null ;
81+ String result = null ;
82+ try (PreparedStatement stmt = conn .prepareStatement ("select version from product_component_version where product like 'Oracle Database%'" ))
83+ {
84+ ResultSet rs = stmt .executeQuery ();
85+
86+ if ( rs .next () )
87+ result = rs .getString (1 );
88+ }
89+
90+ return result ;
91+ }
92+
8193 /**
8294 * Enable the dbms_output buffer with unlimited size.
8395 * @param conn the connection
8496 */
8597 public static void enableDBMSOutput (Connection conn ) {
98+ assert conn != null ;
8699 try (CallableStatement call = conn .prepareCall ("BEGIN dbms_output.enable(NULL); END;" )) {
87100 call .execute ();
88101 } catch (SQLException e ) {
@@ -95,6 +108,7 @@ public static void enableDBMSOutput(Connection conn) {
95108 * @param conn the connection
96109 */
97110 public static void disableDBMSOutput (Connection conn ) {
111+ assert conn != null ;
98112 try (CallableStatement call = conn .prepareCall ("BEGIN dbms_output.disable(); END;" )) {
99113 call .execute ();
100114 } catch (SQLException e ) {
0 commit comments