-
Notifications
You must be signed in to change notification settings - Fork 859
Code sample - 23c BOOLEAN data type with JDBC + SQL #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jeandelavarene
merged 9 commits into
oracle-samples:main
from
juarezjuniorgithub:23c-jdbc-boolean
Jul 1, 2024
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2759054
Added sample code - 23c BOOLEAN data type with JDBC + SQL
juarezjuniorgithub 2b10c6b
Added header with Copyright 2024
juarezjuniorgithub 561afed
code sample adjustments
juarezjuniorgithub 256bd24
additional code sample adjustments
juarezjuniorgithub 5509d19
update to ucp11 per request by jean
juarezjuniorgithub cd87db7
2 spaces indentation + close jdbc resources
juarezjuniorgithub f4fb282
try with resources + 2 spaces indentation for POM
juarezjuniorgithub 403e38c
fixed 2 spaces indentation issues
juarezjuniorgithub d4f0329
Merge branch 'main' into 23c-jdbc-boolean
jeandelavarene File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>com.oracle.dev.jdbc</groupId> | ||
| <artifactId>jdbc-boolean</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
|
|
||
| <name>jdbc-boolean</name> | ||
| <description>jdbc-boolean</description> | ||
| <url> | ||
| https://medium.com/oracledevs/the-new-boolean-data-type-in-oracle-database-23c-with-the-oracle-jdbc-drivers-23c-21c-jdbc-f3252b200838</url> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <maven.compiler.source>21</maven.compiler.source> | ||
| <maven.compiler.target>21</maven.compiler.target> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.oracle.database.jdbc</groupId> | ||
| <artifactId>ojdbc11</artifactId> | ||
| <version>23.4.0.24.05</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.oracle.database.jdbc</groupId> | ||
| <artifactId>ucp</artifactId> | ||
|
||
| <version>23.4.0.24.05</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-api</artifactId> | ||
| <version>2.0.7</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-simple</artifactId> | ||
| <version>2.0.7</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <pluginManagement><!-- lock down plugins versions to avoid using Maven | ||
| defaults (may be moved to parent pom) --> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-clean-plugin</artifactId> | ||
| <version>3.1.0</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-site-plugin</artifactId> | ||
| <version>3.7.1</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-project-info-reports-plugin</artifactId> | ||
| <version>3.0.0</version> | ||
| </plugin> | ||
| <!-- see | ||
| http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
| <plugin> | ||
| <artifactId>maven-resources-plugin</artifactId> | ||
| <version>3.0.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>3.8.0</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>2.22.1</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <version>3.0.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-install-plugin</artifactId> | ||
| <version>2.5.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-deploy-plugin</artifactId> | ||
| <version>2.8.2</version> | ||
| </plugin> | ||
| </plugins> | ||
| </pluginManagement> | ||
| </build> | ||
|
|
||
| </project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; |
68 changes: 68 additions & 0 deletions
68
java/jdbc-boolean/src/main/java/com/oracle/dev/jdbc/QueryWithBooleanDataTypeColumn.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| 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) { | ||
|
|
||
| OracleDataSource ods = null; | ||
| Connection conn = null; | ||
|
|
||
| try { | ||
|
|
||
| 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]"); | ||
|
|
||
| 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(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use 2 space chars in this file.