Skip to content

Commit dd4a337

Browse files
committed
2 parents 8047385 + 638b946 commit dd4a337

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1120
-122
lines changed

exadata-express/Example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Before running this script:
1010
- Install Node.js and node-oracledb
1111
- Install Oracle Instant Client
1212
- Download and install the cloud service wallet
13-
- Modify the connect() call below to use the credentials for your database.
13+
- Modify the getConnection() call below to use the credentials for your database.
1414
See your cloud service's documentation for details.
1515
1616
----------------------------------------------------------------------*/

exadata-express/Example.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
/*----------------------------------------------------------------------
4+
Example.php
5+
6+
Demonstrate how to perform a database insert and query with PHP
7+
in Oracle Database Cloud services such as Exadata Express,
8+
Autonomous Transaction Processing, Autonomous Data Warehouse, and
9+
others.
10+
11+
Before running this script:
12+
- Install PHP and the OCI8 extension
13+
- Install Oracle Instant Client
14+
- Download and install the cloud service wallet
15+
- Modify the oci_connect() call below to use the credentials for your database.
16+
See your cloud service's documentation for details.
17+
18+
----------------------------------------------------------------------*/
19+
20+
// Uncomment for testing
21+
// error_reporting(E_ALL); // In PHP 5.3 use E_ALL|E_STRICT
22+
// ini_set('display_errors', 'On');
23+
24+
// Connect
25+
26+
$c = oci_connect("username", "password", "connect_string");
27+
if (!$c) {
28+
$m = oci_error();
29+
trigger_error("Could not connect to database: ". $m["message"], E_USER_ERROR);
30+
}
31+
32+
// Create a table
33+
34+
$stmtarray = array(
35+
"BEGIN
36+
EXECUTE IMMEDIATE 'DROP TABLE mycloudtab';
37+
EXCEPTION
38+
WHEN OTHERS THEN
39+
IF SQLCODE NOT IN (-00942) THEN
40+
RAISE;
41+
END IF;
42+
END;",
43+
44+
"CREATE TABLE mycloudtab (id NUMBER, data VARCHAR2(20))"
45+
);
46+
47+
foreach ($stmtarray as $stmt) {
48+
$s = oci_parse($c, $stmt);
49+
if (!$s) {
50+
$m = oci_error($c);
51+
trigger_error("Could not parse statement: ". $m["message"], E_USER_ERROR);
52+
}
53+
$r = oci_execute($s);
54+
if (!$r) {
55+
$m = oci_error($s);
56+
trigger_error("Could not execute statement: ". $m["message"], E_USER_ERROR);
57+
}
58+
}
59+
60+
// Insert some data
61+
62+
$data = [ [101, "Alpha" ], [102, "Beta" ], [103, "Gamma" ] ];
63+
64+
$s = oci_parse($c, "INSERT INTO mycloudtab VALUES (:1, :2)");
65+
if (!$s) {
66+
$m = oci_error($c);
67+
trigger_error("Could not parse statement: ". $m["message"], E_USER_ERROR);
68+
}
69+
70+
foreach ($data as $record) {
71+
oci_bind_by_name($s, ":1", $record[0]);
72+
oci_bind_by_name($s, ":2", $record[1]);
73+
oci_execute($s, OCI_NO_AUTO_COMMIT); // for PHP <= 5.3.1 use OCI_DEFAULT instead
74+
if (!$r) {
75+
$m = oci_error($s);
76+
trigger_error("Could not execute statement: ". $m["message"], E_USER_ERROR);
77+
}
78+
}
79+
oci_commit($c);
80+
81+
// Query the data
82+
83+
$s = oci_parse($c, "SELECT * FROM mycloudtab");
84+
if (!$s) {
85+
$m = oci_error($c);
86+
trigger_error("Could not parse statement: ". $m["message"], E_USER_ERROR);
87+
}
88+
$r = oci_execute($s);
89+
if (!$r) {
90+
$m = oci_error($s);
91+
trigger_error("Could not execute statement: ". $m["message"], E_USER_ERROR);
92+
}
93+
94+
echo "<table border='1'>\n";
95+
96+
// Print column headings
97+
98+
$ncols = oci_num_fields($s);
99+
echo "<tr>\n";
100+
for ($i = 1; $i <= $ncols; ++$i) {
101+
$colname = oci_field_name($s, $i);
102+
echo "<th><b>".htmlspecialchars($colname,ENT_QUOTES|ENT_SUBSTITUTE)."</b></th>\n";
103+
}
104+
echo "</tr>\n";
105+
106+
// Print data
107+
108+
while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
109+
echo "<tr>\n";
110+
foreach ($row as $item) {
111+
echo "<td>";
112+
echo $item !== null ? htmlspecialchars($item, ENT_QUOTES|ENT_SUBSTITUTE) : "&nbsp;";
113+
echo "</td>\n";
114+
}
115+
echo "</tr>\n";
116+
}
117+
echo "</table>\n";
118+
119+
?>

java/jdbc/ConnectionSamples/DataSourceSample.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public class DataSourceSample {
3838
// The recommended format of a connection URL is the long format with the
3939
// connection descriptor.
4040
final static String DB_URL= "jdbc:oracle:thin:@myhost:1521/myorcldbservicename";
41-
// For ATP and ADW - use the TNS Alias name along with the TNS_ADMIN
42-
// final static String DB_URL="jdbc:oracle:thin:@myhost:1521@wallet_dbname?TNS_ADMIN=/Users/test/wallet_dbname";
41+
// For ATP and ADW - use the TNS Alias name along with the TNS_ADMIN when using 18.3 JDBC driver
42+
// final static String DB_URL="jdbc:oracle:thin:@wallet_dbname?TNS_ADMIN=/Users/test/wallet_dbname";
43+
// In case of windows, use the following URL
44+
// final static String DB_URL="jdbc:oracle:thin:@wallet_dbname?TNS_ADMIN=C:\\Users\\test\\wallet_dbname";
4345
final static String DB_USER = "hr";
4446
final static String DB_PASSWORD = "hr";
4547

@@ -57,10 +59,7 @@ public static void main(String args[]) throws SQLException {
5759
info.put(OracleConnection.CONNECTION_PROPERTY_USER_NAME, DB_USER);
5860
info.put(OracleConnection.CONNECTION_PROPERTY_PASSWORD, DB_PASSWORD);
5961
info.put(OracleConnection.CONNECTION_PROPERTY_DEFAULT_ROW_PREFETCH, "20");
60-
info.put(OracleConnection.CONNECTION_PROPERTY_THIN_NET_CHECKSUM_TYPES,
61-
"(MD5,SHA1,SHA256,SHA384,SHA512)");
62-
info.put(OracleConnection.CONNECTION_PROPERTY_THIN_NET_CHECKSUM_LEVEL,
63-
"REQUIRED");
62+
6463

6564
OracleDataSource ods = new OracleDataSource();
6665
ods.setURL(DB_URL);

java/jdbc/Tomcat_Servlet/META-INF/context.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename)))"
88

99
/>
10+
11+
<!-- Database resource for connecting to Autonomous Transaction Processing (ATP) -->
12+
<Resource name="tomcat/UCP_atp" auth="Container"
13+
factory="oracle.ucp.jdbc.PoolDataSourceImpl"
14+
type="oracle.ucp.jdbc.PoolDataSource"
15+
description="UCP Pool in Tomcat"
16+
connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource"
17+
minPoolSize="5"
18+
maxPoolSize="50"
19+
initialPoolSize="15"
20+
user="jdbcuser"
21+
password="XXXXXXX
22+
url="jdbc:oracle:thin:@orcldbtest_medium?TNS_ADMIN=/Users/test/ATPTesting/wallet_ORCLDBTEST"
23+
/>
1024
1125
</Context>
1226
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import java.io.IOException;
2+
import java.io.PrintWriter;
3+
import java.sql.Connection;
4+
import java.sql.ResultSet;
5+
import java.sql.SQLException;
6+
import java.sql.Statement;
7+
8+
import javax.naming.Context;
9+
import javax.naming.InitialContext;
10+
import javax.naming.NamingException;
11+
import javax.servlet.ServletException;
12+
import javax.servlet.annotation.WebServlet;
13+
import javax.servlet.http.HttpServlet;
14+
import javax.servlet.http.HttpServletRequest;
15+
import javax.servlet.http.HttpServletResponse;
16+
17+
import oracle.ucp.admin.UniversalConnectionPoolManagerImpl;
18+
import oracle.ucp.jdbc.PoolDataSource;
19+
20+
/**
21+
* Servlet implementation class UCPServlet
22+
*/
23+
@WebServlet("/UCPServlet")
24+
public class UCPServlet extends HttpServlet {
25+
private static final long serialVersionUID = 1L;
26+
27+
/**
28+
* @see HttpServlet#HttpServlet()
29+
*/
30+
public UCPServlet() {
31+
super();
32+
}
33+
34+
/**
35+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
36+
*/
37+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
38+
throws ServletException, IOException {
39+
PrintWriter out = response.getWriter();
40+
41+
out.println("Servlet to test ATP using UCP");
42+
Connection conn = null;
43+
try {
44+
// Get a context for the JNDI look up
45+
PoolDataSource pds = getPoolInstance();
46+
conn = pds.getConnection();
47+
48+
// Prepare a statement to execute the SQL Queries.
49+
Statement statement = conn.createStatement();
50+
// Create table EMP
51+
statement.executeUpdate("create table EMP(EMPLOYEEID NUMBER,"
52+
+ "EMPLOYEENAME VARCHAR2 (20))");
53+
out.println("New table EMP is created");
54+
// Insert some records into the table EMP
55+
statement.executeUpdate("insert into EMP values(1, 'Jennifer Jones')");
56+
statement.executeUpdate("insert into EMP values(2, 'Alex Debouir')");
57+
out.println("Two records are inserted.");
58+
59+
// Update a record on EMP table.
60+
statement.executeUpdate("update EMP set EMPLOYEENAME='Alex Deborie'"
61+
+ " where EMPLOYEEID=2");
62+
out.println("One record is updated.");
63+
64+
// Verify the table EMP
65+
ResultSet resultSet = statement.executeQuery("select * from EMP");
66+
out.println("\nNew table EMP contains:");
67+
out.println("EMPLOYEEID" + " " + "EMPLOYEENAME");
68+
out.println("--------------------------");
69+
while (resultSet.next()) {
70+
out.println(resultSet.getInt(1) + " " + resultSet.getString(2));
71+
}
72+
out.println("\nSuccessfully tested a connection to ATP using UCP");
73+
}
74+
catch (Exception e) {
75+
response.setStatus(500);
76+
response.setHeader("Exception", e.toString());
77+
out.print("\n Web Request failed");
78+
out.print("\n "+e.toString());
79+
e.printStackTrace();
80+
}
81+
finally {
82+
// Clean-up after everything
83+
try (Statement statement = conn.createStatement()) {
84+
statement.execute("drop table EMP");
85+
conn.close();
86+
}
87+
catch (SQLException e) {
88+
System.out.println("UCPServlet - "
89+
+ "doSQLWork()- SQLException occurred : " + e.getMessage());
90+
}
91+
}
92+
}
93+
94+
/* Get the appropriate datasource */
95+
private PoolDataSource getPoolInstance() throws NamingException {
96+
Context ctx;
97+
ctx = new InitialContext();
98+
Context envContext = (Context) ctx.lookup("java:/comp/env");
99+
100+
// Look up a data source
101+
javax.sql.DataSource ds
102+
= (javax.sql.DataSource) envContext.lookup ("tomcat/UCP_atp");
103+
PoolDataSource pds=(PoolDataSource)ds;
104+
105+
return pds;
106+
}
107+
108+
public void destroy() {
109+
try {
110+
111+
UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager()
112+
.destroyConnectionPool(getPoolInstance().getConnectionPoolName());
113+
System.out.println("Pool Destroyed");
114+
} catch (Exception e) {
115+
System.out.println("destroy pool got Exception:");
116+
e.printStackTrace();
117+
}
118+
119+
}
120+
121+
/**
122+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
123+
*/
124+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
125+
126+
}
127+
128+
}

javascript/node-oracledb/README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Node-oracledb Examples
22

3-
This directory contains [node-oracledb 3.0](https://www.npmjs.com/package/oracledb) examples.
3+
This directory contains [node-oracledb 3.1](https://www.npmjs.com/package/oracledb) examples.
44

55
The node-oracledb add-on for Node.js powers high performance Oracle Database applications.
66

@@ -11,7 +11,7 @@ The node-oracledb add-on for Node.js powers high performance Oracle Database app
1111
Issues and questions about node-oracledb can be posted on
1212
[GitHub](https://github.com/oracle/node-oracledb/issues) or
1313
[Slack](https://node-oracledb.slack.com/) ([link to join
14-
Slack](https://join.slack.com/t/node-oracledb/shared_invite/enQtNDI4NTUyNjMzMDA5LWRiZWRkZjQ3NjBhNDUwOGJlNDFiZWJhZTIzYTJkMWQ5N2UwNTg5NzNmNmY1YmZjZGYxNmRhOTkyOTlhMmViNjY)).
14+
Slack](https://node-oracledb.slack.com/join/shared_invite/enQtNDU4Mjc2NzM5OTA2LTdkMzczODY3OGY3MGI0Yjk3NmQ4NDU4MTI2OGVjNTYzMjE5OGY5YzVkNDY4MWNkNjFiMDM2ZDMwOWRjNWVhNTg).
1515

1616
To run the examples:
1717

@@ -22,19 +22,31 @@ To run the examples:
2222
example, to load them in the HR schema run:
2323

2424
```
25-
sqlplus hr/welcome@localhost/orclpdb @demo.sql
25+
sqlplus hr
26+
SQL> @demo.sql
2627
```
2728

28-
- Edit `dbconfig.js` and set your username, password and the database
29+
- Edit `dbconfig.js` and set your username and the database
2930
connection string:
3031

3132
```
3233
module.exports = {
3334
user: "hr",
34-
password: "welcome",
35+
password: process.env.NODE_ORACLEDB_PASSWORD,
3536
connectString:"localhost/orclpdb"
3637
};
38+
```
39+
40+
- Set the environment variable `NODE_ORACLEDB_PASSWORD` to your database schema password.
41+
42+
On Windows:
43+
```
44+
set NODE_ORACLEDB_PASSWORD=...
45+
```
3746

47+
On Linux:
48+
```
49+
export NODE_ORACLEDB_PASSWORD=...
3850
```
3951

4052
- Then run the samples like:

javascript/node-oracledb/calltimeout.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -21,10 +21,12 @@
2121
* DESCRIPTION
2222
* Shows how to time out long running database calls.
2323
* See https://oracle.github.io/node-oracledb/doc/api.html#dbcalltimeouts
24-
* Node-oracledb must be using Oracle Client 18c libraries, or greater.
2524
*
2625
* This example uses Async/Await of Node 8.
2726
*
27+
* This example requires node-oracledb 3 or later.
28+
* Node-oracledb must be using Oracle Client 18c libraries, or greater.
29+
*
2830
*****************************************************************************/
2931

3032
let oracledb = require("oracledb");

javascript/node-oracledb/connect.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* Tests a basic connection to the database.
2323
* See dbconfig.js for information on connectString formats.
2424
*
25+
* For a connection pool example see connectionpool.js
26+
*
2527
*****************************************************************************/
2628

2729
var oracledb = require('oracledb');

0 commit comments

Comments
 (0)