diff --git a/java/jdbc-boolean/pom.xml b/java/jdbc-boolean/pom.xml new file mode 100644 index 00000000..c1c248c2 --- /dev/null +++ b/java/jdbc-boolean/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + com.oracle.dev.jdbc + jdbc-boolean + 1.0-SNAPSHOT + + jdbc-boolean + jdbc-boolean + + https://medium.com/oracledevs/the-new-boolean-data-type-in-oracle-database-23c-with-the-oracle-jdbc-drivers-23c-21c-jdbc-f3252b200838 + + + UTF-8 + 21 + 21 + + + + + com.oracle.database.jdbc + ojdbc11 + 23.4.0.24.05 + + + com.oracle.database.jdbc + ucp11 + 23.4.0.24.05 + + + org.slf4j + slf4j-api + 2.0.7 + + + org.slf4j + slf4j-simple + 2.0.7 + + + + + + + + maven-clean-plugin + 3.1.0 + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + + diff --git a/java/jdbc-boolean/sql/hq_employee.sql b/java/jdbc-boolean/sql/hq_employee.sql new file mode 100644 index 00000000..9b4fdde5 --- /dev/null +++ b/java/jdbc-boolean/sql/hq_employee.sql @@ -0,0 +1,22 @@ +CREATE TABLE HQ_EMPLOYEE +( + "EMP_ID" NUMBER NOT NULL ENABLE, + "NAME" VARCHAR2(20 BYTE) DEFAULT NULL, + "ROLE" VARCHAR2(20 BYTE) DEFAULT NULL, + "ACTIVE" BOOLEAN DEFAULT NULL, + PRIMARY KEY ("EMP_ID") +); +COMMIT; + +DESCRIBE HQ_EMPLOYEE; + +-- BOOLEAN = TRUE OR FALSE +INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (1, 'Juarez', 'Developer Evangelist', TRUE); +INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (2, 'David', 'DevOps Architect', FALSE); +-- BOOLEAN = 1 OR 0 +INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (3, 'Karl', 'Product Manager', 1); +INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (4, 'Patrick', 'Software Architect', 0); +-- BOOLEAN = 'Y' OR 'N' +INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (5, 'Robert', 'Software Engineer', 'Y'); +INSERT INTO HQ_EMPLOYEE (emp_id, name, role, active) VALUES (6, 'James', 'Program Manager', 'N'); +COMMIT; \ No newline at end of file diff --git a/java/jdbc-boolean/src/main/java/com/oracle/dev/jdbc/QueryWithBooleanDataTypeColumn.java b/java/jdbc-boolean/src/main/java/com/oracle/dev/jdbc/QueryWithBooleanDataTypeColumn.java new file mode 100644 index 00000000..3697e21c --- /dev/null +++ b/java/jdbc-boolean/src/main/java/com/oracle/dev/jdbc/QueryWithBooleanDataTypeColumn.java @@ -0,0 +1,61 @@ +/* + Copyright (c) 2024, Oracle and/or its affiliates. + + This software is dual-licensed to you under the Universal Permissive License + (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License + 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose + either license. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.oracle.dev.jdbc; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import oracle.jdbc.pool.OracleDataSource; + +public class QueryWithBooleanDataTypeColumn { + + public static void main(String[] args) throws SQLException { + + OracleDataSource ods = new OracleDataSource(); + + // jdbc:oracle:thin@[hostname]:[port]/[DB service/name] + ods.setURL("jdbc:oracle:thin:@localhost:1521/FREEPDB1"); + ods.setUser("[Username]"); + ods.setPassword("[Password]"); + + try (Connection conn = ods.getConnection(); + // please check hq_employee.sql under the /sql directory + PreparedStatement stmt = conn.prepareStatement("SELECT * FROM HQ_EMPLOYEE WHERE ACTIVE"); + ResultSet rslt = stmt.executeQuery();) { + + StringBuilder sb = new StringBuilder(); + while (rslt.next()) { + sb.append(rslt.getInt(1)).append("|").append(rslt.getString(2)).append("|").append(rslt.getString(3)) + .append("|").append(rslt.getBoolean(4)).append("\n"); + + } + System.out.println(sb.toString()); + + } catch (SQLException e) { + e.printStackTrace(); + } + + } + +}