Skip to content

Commit eb7f6ae

Browse files
Code sample - 23c JDBC Docker Windows (#313)
* Code sample - 23c JDBC Docker Windows * additional adjustments * fix indentation and close JDBC resources
1 parent 5e2276d commit eb7f6ae

File tree

2 files changed

+127
-0
lines changed
  • java/java-jdbc-db23cfree-dev

2 files changed

+127
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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>java-jdbc-db23cfree-dev</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
12+
<name>java-jdbc-db23cfree-dev</name>
13+
<description>Oracle Database 23c Free — Developer Release for Java Developers
14+
with Docker on Windows</description>
15+
<url>
16+
https://medium.com/oracledevs/oracle-database-23c-free-developer-release-for-java-developers-with-docker-on-windows-b164a7a61a91</url>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<maven.compiler.source>21</maven.compiler.source>
21+
<maven.compiler.target>21</maven.compiler.target>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>com.oracle.database.jdbc</groupId>
27+
<artifactId>ojdbc11</artifactId>
28+
<version>23.4.0.24.05</version>
29+
</dependency>
30+
</dependencies>
31+
32+
<build>
33+
<pluginManagement><!-- lock down plugins versions to avoid using Maven
34+
defaults (may be moved to parent pom) -->
35+
<plugins>
36+
<plugin>
37+
<artifactId>maven-clean-plugin</artifactId>
38+
<version>3.1.0</version>
39+
</plugin>
40+
<plugin>
41+
<artifactId>maven-site-plugin</artifactId>
42+
<version>3.7.1</version>
43+
</plugin>
44+
<plugin>
45+
<artifactId>maven-project-info-reports-plugin</artifactId>
46+
<version>3.0.0</version>
47+
</plugin>
48+
<!-- see
49+
http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
50+
<plugin>
51+
<artifactId>maven-resources-plugin</artifactId>
52+
<version>3.0.2</version>
53+
</plugin>
54+
<plugin>
55+
<artifactId>maven-compiler-plugin</artifactId>
56+
<version>3.8.0</version>
57+
</plugin>
58+
<plugin>
59+
<artifactId>maven-surefire-plugin</artifactId>
60+
<version>2.22.1</version>
61+
</plugin>
62+
<plugin>
63+
<artifactId>maven-jar-plugin</artifactId>
64+
<version>3.0.2</version>
65+
</plugin>
66+
<plugin>
67+
<artifactId>maven-install-plugin</artifactId>
68+
<version>2.5.2</version>
69+
</plugin>
70+
<plugin>
71+
<artifactId>maven-deploy-plugin</artifactId>
72+
<version>2.8.2</version>
73+
</plugin>
74+
</plugins>
75+
</pluginManagement>
76+
</build>
77+
78+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 App {
32+
public static void main(String[] args) throws SQLException {
33+
OracleDataSource ods = new OracleDataSource();
34+
// jdbc:oracle:thin@[hostname]:[port]/[DB service/name]
35+
ods.setURL("jdbc:oracle:thin:@localhost:1521/FREEPDB1");
36+
ods.setUser("[Username]");
37+
ods.setPassword("[Password]");
38+
try (Connection conn = ods.getConnection();
39+
PreparedStatement stmt = conn
40+
.prepareStatement("SELECT 'Hello World!' FROM dual");
41+
ResultSet rslt = stmt.executeQuery();) {
42+
while (rslt.next()) {
43+
System.out.println(rslt.getString(1));
44+
}
45+
} catch (SQLException e) {
46+
e.printStackTrace();
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)