Skip to content

Commit bb3ff39

Browse files
Code sample - 23c BOOLEAN data type with JDBC + SQL (#310)
* Added sample code - 23c BOOLEAN data type with JDBC + SQL * Added header with Copyright 2024 * code sample adjustments * additional code sample adjustments * update to ucp11 per request by jean * 2 spaces indentation + close jdbc resources * try with resources + 2 spaces indentation for POM * fixed 2 spaces indentation issues --------- Co-authored-by: Jean de Lavarene <jean.de.lavarene@oracle.com>
1 parent 3e0a59e commit bb3ff39

File tree

3 files changed

+175
-0
lines changed

3 files changed

+175
-0
lines changed

java/jdbc-boolean/pom.xml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.oracle.dev.jdbc</groupId>
9+
<artifactId>jdbc-boolean</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
12+
<name>jdbc-boolean</name>
13+
<description>jdbc-boolean</description>
14+
<url>
15+
https://medium.com/oracledevs/the-new-boolean-data-type-in-oracle-database-23c-with-the-oracle-jdbc-drivers-23c-21c-jdbc-f3252b200838</url>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<maven.compiler.source>21</maven.compiler.source>
20+
<maven.compiler.target>21</maven.compiler.target>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>com.oracle.database.jdbc</groupId>
26+
<artifactId>ojdbc11</artifactId>
27+
<version>23.4.0.24.05</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.oracle.database.jdbc</groupId>
31+
<artifactId>ucp11</artifactId>
32+
<version>23.4.0.24.05</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.slf4j</groupId>
36+
<artifactId>slf4j-api</artifactId>
37+
<version>2.0.7</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.slf4j</groupId>
41+
<artifactId>slf4j-simple</artifactId>
42+
<version>2.0.7</version>
43+
</dependency>
44+
</dependencies>
45+
46+
<build>
47+
<pluginManagement><!-- lock down plugins versions to avoid using Maven
48+
defaults (may be moved to parent pom) -->
49+
<plugins>
50+
<plugin>
51+
<artifactId>maven-clean-plugin</artifactId>
52+
<version>3.1.0</version>
53+
</plugin>
54+
<plugin>
55+
<artifactId>maven-site-plugin</artifactId>
56+
<version>3.7.1</version>
57+
</plugin>
58+
<plugin>
59+
<artifactId>maven-project-info-reports-plugin</artifactId>
60+
<version>3.0.0</version>
61+
</plugin>
62+
<!-- see
63+
http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
64+
<plugin>
65+
<artifactId>maven-resources-plugin</artifactId>
66+
<version>3.0.2</version>
67+
</plugin>
68+
<plugin>
69+
<artifactId>maven-compiler-plugin</artifactId>
70+
<version>3.8.0</version>
71+
</plugin>
72+
<plugin>
73+
<artifactId>maven-surefire-plugin</artifactId>
74+
<version>2.22.1</version>
75+
</plugin>
76+
<plugin>
77+
<artifactId>maven-jar-plugin</artifactId>
78+
<version>3.0.2</version>
79+
</plugin>
80+
<plugin>
81+
<artifactId>maven-install-plugin</artifactId>
82+
<version>2.5.2</version>
83+
</plugin>
84+
<plugin>
85+
<artifactId>maven-deploy-plugin</artifactId>
86+
<version>2.8.2</version>
87+
</plugin>
88+
</plugins>
89+
</pluginManagement>
90+
</build>
91+
92+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CREATE TABLE HQ_EMPLOYEE
2+
(
3+
"EMP_ID" NUMBER NOT NULL ENABLE,
4+
"NAME" VARCHAR2(20 BYTE) DEFAULT NULL,
5+
"ROLE" VARCHAR2(20 BYTE) DEFAULT NULL,
6+
"ACTIVE" BOOLEAN DEFAULT NULL,
7+
PRIMARY KEY ("EMP_ID")
8+
);
9+
COMMIT;
10+
11+
DESCRIBE HQ_EMPLOYEE;
12+
13+
-- BOOLEAN = TRUE OR FALSE
14+
INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (1, 'Juarez', 'Developer Evangelist', TRUE);
15+
INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (2, 'David', 'DevOps Architect', FALSE);
16+
-- BOOLEAN = 1 OR 0
17+
INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (3, 'Karl', 'Product Manager', 1);
18+
INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (4, 'Patrick', 'Software Architect', 0);
19+
-- BOOLEAN = 'Y' OR 'N'
20+
INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (5, 'Robert', 'Software Engineer', 'Y');
21+
INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (6, 'James', 'Program Manager', 'N');
22+
COMMIT;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright (c) 2024, Oracle and/or its affiliates.
3+
4+
This software is dual-licensed to you under the Universal Permissive License
5+
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
6+
2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
7+
either license.
8+
9+
Licensed under the Apache License, Version 2.0 (the "License");
10+
you may not use this file except in compliance with the License.
11+
You may obtain a copy of the License at
12+
13+
https://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+
*/
21+
22+
package com.oracle.dev.jdbc;
23+
24+
import java.sql.Connection;
25+
import java.sql.PreparedStatement;
26+
import java.sql.ResultSet;
27+
import java.sql.SQLException;
28+
29+
import oracle.jdbc.pool.OracleDataSource;
30+
31+
public class QueryWithBooleanDataTypeColumn {
32+
33+
public static void main(String[] args) throws SQLException {
34+
35+
OracleDataSource ods = new OracleDataSource();
36+
37+
// jdbc:oracle:thin@[hostname]:[port]/[DB service/name]
38+
ods.setURL("jdbc:oracle:thin:@localhost:1521/FREEPDB1");
39+
ods.setUser("[Username]");
40+
ods.setPassword("[Password]");
41+
42+
try (Connection conn = ods.getConnection();
43+
// please check hq_employee.sql under the /sql directory
44+
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM HQ_EMPLOYEE WHERE ACTIVE");
45+
ResultSet rslt = stmt.executeQuery();) {
46+
47+
StringBuilder sb = new StringBuilder();
48+
while (rslt.next()) {
49+
sb.append(rslt.getInt(1)).append("|").append(rslt.getString(2)).append("|").append(rslt.getString(3))
50+
.append("|").append(rslt.getBoolean(4)).append("\n");
51+
52+
}
53+
System.out.println(sb.toString());
54+
55+
} catch (SQLException e) {
56+
e.printStackTrace();
57+
}
58+
59+
}
60+
61+
}

0 commit comments

Comments
 (0)