-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDBHelper.java
More file actions
55 lines (48 loc) · 1.64 KB
/
DBHelper.java
File metadata and controls
55 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.utplsql.api;
import oracle.jdbc.OracleTypes;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
/**
* Database utility functions.
*/
public final class DBHelper {
private DBHelper() {}
/**
* Return a new sys_guid from database.
* @param conn the connection
* @return the new id string
* @throws SQLException any database error
*/
public static String newSysGuid(Connection conn) throws SQLException {
CallableStatement callableStatement = null;
try {
callableStatement = conn.prepareCall("BEGIN ? := sys_guid(); END;");
callableStatement.registerOutParameter(1, OracleTypes.RAW);
callableStatement.executeUpdate();
return callableStatement.getString(1);
} finally {
if (callableStatement != null)
callableStatement.close();
}
}
/**
* Return the current schema name.
* @param conn the connection
* @return the schema name
* @throws SQLException any database error
*/
public static String getCurrentSchema(Connection conn) throws SQLException {
CallableStatement callableStatement = null;
try {
callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;");
callableStatement.registerOutParameter(1, Types.VARCHAR);
callableStatement.executeUpdate();
return callableStatement.getString(1);
} finally {
if (callableStatement != null)
callableStatement.close();
}
}
}