Skip to content

Commit 3964bbb

Browse files
committed
2 parents 1ce718b + 5475320 commit 3964bbb

Some content is hidden

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

43 files changed

+604
-299
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ This repository stores a variety of examples demonstrating how to use the Oracle
88
| [java](./java) | Java based examples |
99
| [javascript](./javascript) | JavaScript based examples |
1010
| [optimizer](./optimizer) | Oracle Optmizer and Optimizer Stats examples |
11+
| [plsql](./plsql) | PL/SQL based examples |
1112
| [python](./python) | Python based examples |
13+
| [ruby](./ruby) | Ruby based examples |
1214
| [sql](./sql) | SQL based examples |
13-
| [sqldeveloper](./sqldeveloper) | [SQL Developer](http://www.oracle.com/technetwork/developer-tools/sql-developer/) Examples |
15+
| [sqldeveloper](./sqldeveloper) | [SQL Developer](http://www.oracle.com/technetwork/developer-tools/sql-developer/) examples |
1416

1517
## Documentation
1618
You can find the online documentation of the Oracle Database under [docs.oracle.com/en/database/](http://docs.oracle.com/en/database/)

java/jdbc/ConnectionManagementSamples/DataSourceSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ such as Universal Connection Pool (UCP), can be configured to use an
3737
public class DataSourceSample {
3838
// The recommended format of a connection URL is the long format with the
3939
// connection descriptor.
40-
final static String DB_URL= "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename)))";
40+
final static String DB_URL= "jdbc:oracle:thin:@myhost:1521/myorcldbservicename";
4141
final static String DB_USER = "hr";
4242
final static String DB_PASSWORD = "hr";
4343

java/ojvm/SODA.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ The goal of this write up is to furnish the steps for running testSODA.java in O
88

99
(i) Download the [latest orajsoda.jar](https://github.com/oracle/soda-for-java/releases) currently orajsoda-1.0.4.jar
1010

11-
(ii) Upload orasoda.jar in your database schema
12-
13-
loadjava -r -v -u hr/hr orajsoda-1.0.4.jar
14-
15-
(iii) Load the [latest javax.json-1.0.4.jar](https://mvnrepository.com/artifact/org.glassfish/javax.json/1.0.4)
11+
(ii) Load the [latest javax.json-1.0.4.jar](https://mvnrepository.com/artifact/org.glassfish/javax.json/1.0.4)
1612

1713
loadjava -r -v -u hr/hr javax.json-1.0.4.jar
14+
15+
(iii) Upload orasoda.jar in your database schema
16+
17+
loadjava -r -v -u hr/hr orajsoda-1.0.5.jar
1818

1919
**Prep testSODA.java for OJVM**
2020

java/ucp/ConnectionManagementSamples/UCPSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The code sample demonstrates Universal Connection Pool (UCP) as a client
3030
import oracle.ucp.jdbc.PoolDataSource;
3131

3232
public class UCPSample {
33-
final static String DB_URL= "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename)))";
33+
final static String DB_URL= "jdbc:oracle:thin:@myhost:1521/myorcldbservicename";
3434
// Use TNS alias when using tnsnames.ora. Use it while connecting to the database service on cloud.
3535
// final static String DB_URL= "jdbc:oracle:thin:@orcldbaccess";
3636
final static String DB_USER = "hr";

javascript/node-oracledb/README.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
1-
These are examples for the [node-oracledb 1.13 driver](https://www.npmjs.com/package/oracledb)
1+
# Node-oracledb Examples
22

3-
The node-oracledb add-on for Node.js powers high performance Oracle Database applications.
3+
This directory contains [node-oracledb 2.0](https://www.npmjs.com/package/oracledb) examples.
44

5-
[node-oracledb installation instructions](https://github.com/oracle/node-oracledb/blob/master/INSTALL.md)
5+
The node-oracledb add-on for Node.js powers high performance Oracle Database applications.
66

77
[Node-oracledb documentation](https://github.com/oracle/node-oracledb/blob/master/doc/api.md)
88

99
[Issues and questions](https://github.com/oracle/node-oracledb/issues)
1010

11-
After installing node-oracledb, the demos can be run by editing
12-
dbconfig.js to set your database credentials, creating the schema
13-
objects with demo.sql, and then executing each JavaScript file with
14-
Node.js.
11+
To run the examples:
12+
13+
- [Install node-oracledb](https://github.com/oracle/node-oracledb/blob/master/INSTALL.md).
14+
15+
16+
- Use `demo.sql` to create schema objects used by the samples. For
17+
example, to load them in the HR schema run:
18+
19+
```
20+
sqlplus hr/welcome@localhost/orclpdb @demo.sql
21+
```
22+
23+
- Edit `dbconfig.js` and set your username, password and the database
24+
connection string:
25+
26+
```
27+
module.exports = {
28+
user: "hr",
29+
password: "welcome",
30+
connectString:"localhost/orclpdb"
31+
};
32+
33+
```
34+
35+
- Then run the samples like:
36+
37+
```
38+
node select1.js
39+
```
40+
41+
The demonstration objects can be dropped with `demodrop.sql`:
42+
43+
```
44+
sqlplus hr/welcome@localhost/orclpdb @demodrop.sql
45+
```

javascript/node-oracledb/blobhttp.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ function init() {
5757

5858
// Create HTTP server and listen on port 'httpPort'
5959
http
60-
.createServer(function(request, response) {
61-
handleRequest(request, response);
62-
})
63-
.listen(httpPort);
60+
.createServer(function(request, response) {
61+
handleRequest(request, response);
62+
})
63+
.listen(httpPort);
6464

6565
console.log("Server running. Try requesting: http://localhost:" + httpPort + "/getimage");
6666
});
@@ -140,13 +140,13 @@ function handleRequest(request, response) {
140140
}
141141

142142
process
143-
.on('SIGTERM', function() {
144-
console.log("\nTerminating");
145-
process.exit(0);
146-
})
147-
.on('SIGINT', function() {
148-
console.log("\nTerminating");
149-
process.exit(0);
150-
});
143+
.on('SIGTERM', function() {
144+
console.log("\nTerminating");
145+
process.exit(0);
146+
})
147+
.on('SIGINT', function() {
148+
console.log("\nTerminating");
149+
process.exit(0);
150+
});
151151

152152
init();

javascript/node-oracledb/date.js

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

33
/******************************************************************************
44
*
@@ -50,17 +50,17 @@ var dorelease = function(conn) {
5050

5151
var docleanup = function (conn, cb) {
5252
conn.execute(
53-
"BEGIN " +
54-
" DECLARE" +
55-
" e_table_exists EXCEPTION;" +
56-
" PRAGMA EXCEPTION_INIT(e_table_exists, -00942);" +
57-
" BEGIN" +
58-
" EXECUTE IMMEDIATE ('DROP TABLE datetest');" +
59-
" EXCEPTION" +
60-
" WHEN e_table_exists" +
61-
" THEN NULL;" +
62-
" END; " +
63-
"END;",
53+
`BEGIN
54+
DECLARE
55+
e_table_exists EXCEPTION;
56+
PRAGMA EXCEPTION_INIT(e_table_exists, -00942);
57+
BEGIN
58+
EXECUTE IMMEDIATE ('DROP TABLE datetest');
59+
EXCEPTION
60+
WHEN e_table_exists
61+
THEN NULL;
62+
END;
63+
END;`,
6464
function(err) {
6565
return cb(err, conn);
6666
});

javascript/node-oracledb/dbconfig.js

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

33
/******************************************************************************
44
*
@@ -34,7 +34,7 @@
3434
* [//]host_name[:port][/service_name][:server_type][/instance_name]
3535
*
3636
* Commonly just the host_name and service_name are needed
37-
* e.g. "localhost/orcl" or "localhost/XE"
37+
* e.g. "localhost/orclpdb" or "localhost/XE"
3838
*
3939
* If using a tnsnames.ora file, the file can be in a default
4040
* location such as $ORACLE_HOME/network/admin/tnsnames.ora or
@@ -76,7 +76,7 @@ module.exports = {
7676

7777
// For information on connection strings see:
7878
// https://github.com/oracle/node-oracledb/blob/master/doc/api.md#connectionstrings
79-
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "localhost/orcl",
79+
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "localhost/orclpdb",
8080

8181
// Setting externalAuth is optional. It defaults to false. See:
8282
// https://github.com/oracle/node-oracledb/blob/master/doc/api.md#extauth

javascript/node-oracledb/dbmsoutputgetline.js

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

33
/******************************************************************************
44
*
@@ -65,10 +65,10 @@ var enableDbmsOutput = function (conn, cb) {
6565

6666
var createDbmsOutput = function (conn, cb) {
6767
conn.execute(
68-
"BEGIN " +
69-
"DBMS_OUTPUT.PUT_LINE('Hello, Oracle!');" +
70-
"DBMS_OUTPUT.PUT_LINE('Hello, Node!');" +
71-
"END;",
68+
`BEGIN
69+
DBMS_OUTPUT.PUT_LINE('Hello, Oracle!');
70+
DBMS_OUTPUT.PUT_LINE('Hello, Node!');
71+
END;`,
7272
function(err) { return cb(err, conn); });
7373
};
7474

javascript/node-oracledb/dbmsoutputpipe.js

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

33
/******************************************************************************
44
*
@@ -68,7 +68,8 @@ var doit = function(pool) {
6868
enableDbmsOutput,
6969
createDbmsOutput,
7070
fetchDbmsOutput,
71-
printDbmsOutput
71+
printDbmsOutput,
72+
closeRS
7273
],
7374
function (err, conn) {
7475
if (err) { console.error("In waterfall error cb: ==>", err, "<=="); }
@@ -84,10 +85,10 @@ var enableDbmsOutput = function (conn, cb) {
8485

8586
var createDbmsOutput = function (conn, cb) {
8687
conn.execute(
87-
"BEGIN " +
88-
"DBMS_OUTPUT.PUT_LINE('Hello, Oracle!');" +
89-
"DBMS_OUTPUT.PUT_LINE('Hello, Node!');" +
90-
"END;",
88+
`BEGIN
89+
DBMS_OUTPUT.PUT_LINE('Hello, Oracle!');
90+
DBMS_OUTPUT.PUT_LINE('Hello, Node!');
91+
END;`,
9192
function(err) { return cb(err, conn); });
9293
};
9394

@@ -118,12 +119,18 @@ var fetchRowsFromRS = function(conn, resultSet, numRows, cb) {
118119
numRows,
119120
function (err, rows) {
120121
if (err) {
121-
return cb(err, conn);
122+
return cb(err, conn, resultSet);
122123
} else if (rows.length > 0) {
123124
console.log(rows);
124125
return fetchRowsFromRS(conn, resultSet, numRows, cb);
125126
} else {
126-
return cb(null, conn);
127+
return cb(null, conn, resultSet);
127128
}
128129
});
129130
};
131+
132+
var closeRS = function(conn, resultSet, cb) {
133+
resultSet.close(function(err) {
134+
return cb(err, conn);
135+
});
136+
};

0 commit comments

Comments
 (0)