11package org .utplsql .api ;
22
33import oracle .jdbc .OracleTypes ;
4+ import org .utplsql .api .exception .DatabaseNotCompatibleException ;
45
56import java .sql .*;
67
@@ -94,20 +95,25 @@ public static boolean versionCompatibilityCheck(Connection conn)
9495 }
9596
9697
97- /** Checks if actual API-version is compatible with utPLSQL database version and throws a RuntimeException if not
98- * Throws a RuntimeException if version compatibility can not be checked.
98+ /** Checks if actual API-version is compatible with utPLSQL database version and throws a DatabaseNotCompatibleException if not
99+ * Throws a DatabaseNotCompatibleException if version compatibility can not be checked.
99100 *
100101 * @param conn Active db connection
101102 */
102- public static void failOnVersionCompatibilityCheckFailed ( Connection conn )
103+ public static void failOnVersionCompatibilityCheckFailed ( Connection conn ) throws DatabaseNotCompatibleException
103104 {
104105 try {
105106 if (!versionCompatibilityCheck (conn ))
106- throw new RuntimeException ("API-Version " + UTPLSQL_COMPATIBILITY_VERSION + " not compatible with database. Aborting." );
107+ {
108+ // Try to find out Framework Version
109+ Version v = DBHelper .getDatabaseFrameworkVersion (conn );
110+
111+ throw new DatabaseNotCompatibleException ( v .getVersionString () );
112+ }
107113 }
108114 catch ( SQLException e )
109115 {
110- throw new RuntimeException ("Compatibility-check failed with error. Aborting." , e );
116+ throw new DatabaseNotCompatibleException ("Compatibility-check failed with error. Aborting." , UTPLSQL_COMPATIBILITY_VERSION , "Unknown " , e );
111117 }
112118 }
113119
@@ -120,9 +126,9 @@ public static void failOnVersionCompatibilityCheckFailed( Connection conn )
120126 public static Version getDatabaseFrameworkVersion ( Connection conn )
121127 throws SQLException {
122128 Version result = new Version ("" );
123- try (Statement stmt = conn .prepareStatement ("select ut_runner.version() from dual" ))
129+ try (PreparedStatement stmt = conn .prepareStatement ("select ut_runner.version() from dual" ))
124130 {
125- ResultSet rs = stmt .getResultSet ();
131+ ResultSet rs = stmt .executeQuery ();
126132
127133 if ( rs .next () )
128134 result = new Version (rs .getString (1 ));
0 commit comments