1- /* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.*/
1+ /* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+ Licensed under the Universal Permissive License v 1.0
3+ as shown at http://oss.oracle.com/licenses/upl
4+ */
25
36/*
47 DESCRIPTION
5- The code sample connects to the Oracle Database and creates a table 'todoitem'.
8+ The code sample connects to the Oracle Database and creates a table 'todoitem'.
9+ It inserts few records into this table and displays the list of tasks and task completion status.
610 Edit this file and update the connection URL along with the database username and password
711 that point to your database.
812
@@ -27,18 +31,19 @@ public class QuickStart {
2731 // Change this URL to match your target Oracle database (XE or else)
2832 final static String DB_URL ="jdbc:oracle:thin:@//localhost:1521/XEPDB1" ;
2933 // Enter the database user
30- final static String DB_USER = "jdbctest " ;
34+ final static String DB_USER = "<db-user> " ;
3135 // Enter the database password
32- final static String DB_PASSWORD = "jdbctest " ;
36+ final static String DB_PASSWORD = "<db-password> " ;
3337 final static String CONN_FACTORY_CLASS_NAME ="oracle.jdbc.pool.OracleDataSource" ;
3438
3539 /*
36- * The sample demonstrates UCP as client side connection pool.
40+ * The sample creates a table 'todoitem' that lists tasks and task completion status.
41+ * Requirement: database connection string, database user and database password
3742 */
3843 public static void main (String args []) throws Exception {
44+
3945 // Get the PoolDataSource for UCP
4046 PoolDataSource pds = PoolDataSourceFactory .getPoolDataSource ();
41-
4247 // Set the connection factory
4348 pds .setConnectionFactoryClassName (CONN_FACTORY_CLASS_NAME );
4449 pds .setURL (DB_URL );
@@ -59,7 +64,6 @@ public static void main(String args[]) throws Exception {
5964 + pds .getAvailableConnectionsCount ());
6065 System .out .println ("Borrowed connections after checkout: "
6166 + pds .getBorrowedConnectionsCount ());
62- // Perform a database operation
6367 doSQLWork (conn );
6468 }
6569
@@ -70,30 +74,30 @@ public static void main(String args[]) throws Exception {
7074 }
7175
7276 /*
73- * Creates a todoitem table and insert few rows, and select operations on
74- * the new table created. Remove the table after verifying the data.
77+ * Creates a ' todoitem' table, insert few rows, and select the data from
78+ * the table created. Remove the table after verifying the data.
7579 */
7680 public static void doSQLWork (Connection conn ) {
7781 try {
7882 conn .setAutoCommit (false );
79- // Prepare a statement to execute the SQL Queries .
83+ // Prepare a statement to execute the SQL Statement .
8084 Statement statement = conn .createStatement ();
8185
86+ // Create a table 'todoitem'
8287 String createSQL = "CREATE TABLE todoitem "
8388 + "(id NUMBER GENERATED ALWAYS AS IDENTITY,"
8489 + " description VARCHAR2(4000), "
8590 + " creation_ts TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,"
8691 + " done NUMBER(1, 0), PRIMARY KEY(id))" ;
87-
88- // Create a table "todoitem"
92+
8993 statement .executeUpdate (createSQL );
90- System .out .println ("New table todoitem is created" );
94+ System .out .println ("New table ' todoitem' is created" );
9195
9296 //Insert sample data
9397 String [] description = { "Task 1" , "Task 2" , "Task 3" , "Task 4" , "Task 5" };
9498 int [] done = { 0 , 0 , 1 , 0 , 1 };
9599
96- // Insert some records into the table CUSTOMER
100+ // Insert some records into the table 'todoitem'
97101 PreparedStatement prepStatement = conn .prepareStatement ("INSERT INTO "
98102 + " todoitem (description, done) VALUES(?, ?)" );
99103 for (int row = 0 ; row < description .length ; row ++) {
@@ -103,9 +107,9 @@ public static void doSQLWork(Connection conn) {
103107 }
104108 prepStatement .executeBatch ();
105109
106- System .out .println ("Two records are inserted. " );
110+ System .out .println ("New records are inserted" );
107111
108- // Verify the table "todoitem"
112+ // Verify the data from the table "todoitem"
109113 ResultSet resultSet = statement .executeQuery ("SELECT DESCRIPTION, DONE FROM TODOITEM" );
110114 System .out .println ("\n New table 'todoitem' contains:" );
111115 System .out .println ("DESCRIPTION" + "\t " + "DONE" );
0 commit comments