3
3
/*
4
4
DESCRIPTION
5
5
The code sample shows how to use the JDBC driver to establish a connection
6
- to the Autonomous Database (ADB) using database token
6
+ to the Autonomous Database (ADB) using access token
7
7
issued by the OCI Identity service.
8
-
9
- You need to use either JDBC driver to use
10
- database token authenticatio.
11
8
12
- Step 1: Enter the DB_URL to pointing to your Autonomous Database (ADB)
13
- Step 2: Make sure to have either 21.4.0.0.1 or 19.13.0.0.1 JDBC driver
14
- in the classpath.
15
- Step 2 : Compile and Run the sample JDBCDBTokenSample
9
+ Step 1: Enter the DB_URL to pointing to your Autonomous Database (ADB)
10
+ Step 2: Make sure to have either 21.4.0.0.1 or 19.13.0.0.1 JDBC driver
11
+ in the classpath.
12
+ Step 3 : Compile and run the sample JDBCDBTokenSample
16
13
17
14
NOTES
18
- Use JDK 1.7 and above
15
+ Use JDK8 and above
19
16
MODIFIED (MM/DD/YY)
20
17
nbsundar 1/7/21 - Creation
21
18
*/
@@ -38,26 +35,25 @@ public class JDBCDBTokenSample {
38
35
// Download the wallet zip file and provide the path to the zip file as TNS_ADMIN
39
36
// Note that you need to pass the property oracle.jdbc.tokenAuthentication=OCI_TOKEN for token authentication
40
37
final static String DB_URL ="jdbc:oracle:thin:@dbname_high?TNS_ADMIN=/Users/user/wallet/Wallet_dbname&oracle.jdbc.tokenAuthentication=OCI_TOKEN" ;
41
- // If mutla TLS(mTLS) is disabled then, ADB connection does not require wallets.
38
+ // If mutual TLS(mTLS) is disabled then, ADB connection does not require wallets.
42
39
// Copy the connection string from "DB Connection" tab from "Connection Strings" section choosing "TLS" in the dropdown
43
40
//final static String DB_URL="jdbc:oracle:thin:@(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.us-phoenix-1.oraclecloud.com))(connect_data=(service_name=gebqqeredfsozhjbqbs_dbname_medium.adb.oraclecloud.com)))?oracle.jdbc.tokenAuthentication=OCI_TOKEN";
41
+ // Another way to enable token authentication in the long form connection string.
42
+ final static String DB_URL ="jdbc:oracle:thin:@(description="
43
+ + "(retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.us-phoenix-1.oraclecloud.com))"
44
+ + "(security=(token_auth=OCI_TOKEN))"
45
+ + "(connect_data=(service_name=gebqqeredfsozhjbqbs_dbname_medium.adb.oraclecloud.com)))?oracle.jdbc.tokenAuthentication=OCI_TOKEN" ;
44
46
45
47
46
48
public static void main (String args []) throws SQLException {
47
49
48
50
// For more connection related properties. Refer to
49
51
// the OracleConnection interface.
50
52
Properties properties = new Properties ();
51
-
52
- properties .put (OracleConnection .CONNECTION_PROPERTY_DEFAULT_ROW_PREFETCH , "20" );
53
- properties .put (OracleConnection .CONNECTION_PROPERTY_THIN_NET_CHECKSUM_TYPES ,
54
- "(MD5,SHA1,SHA256,SHA384,SHA512)" );
55
- properties .put (OracleConnection .CONNECTION_PROPERTY_THIN_NET_CHECKSUM_LEVEL ,
56
- "REQUIRED" );
57
- // Connection property to enable database token authentication.
53
+
54
+ //Connection property to enable IAM token authentication.
58
55
// properties.put(OracleConnection.CONNECTION_PROPERTY_TOKEN_AUTHENTICATION, "OCI_TOKEN");
59
-
60
-
56
+
61
57
OracleDataSource ods = new OracleDataSource ();
62
58
ods .setURL (DB_URL );
63
59
ods .setConnectionProperties (properties );
0 commit comments