Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ea363b4

Browse files
Code sample - 23c JDBC Driver GraalVM Native Executable (#316)
* Code sample - 23c JDBC Driver GraalVM Native Executable * code sample adjustments * code sample adjustments * fix indentation + close JDBC resources
1 parent eb7f6ae commit ea363b4

File tree

4 files changed

+368
-0
lines changed

4 files changed

+368
-0
lines changed
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Java related
2+
target/
3+
*.jar
4+
*.war
5+
*.ear
6+
*.class
7+
8+
# Log file
9+
*.log
10+
11+
# Package Files
12+
*.jar
13+
*.war
14+
*.nar
15+
*.ear
16+
*.zip
17+
*.tar.gz
18+
*.rar
19+
20+
# JVM crash logs - http://www.java.com/en/download/help/error_hotspot.xml
21+
hs_err_pid*
22+
23+
# Eclipse.gitignore - https://github.com/github/gitignore/blob/main/Global/Eclipse.gitignore
24+
.metadata
25+
.classpath
26+
.project
27+
bin/
28+
tmp/
29+
*.tmp
30+
*.bak
31+
*.swp
32+
*~.nib
33+
local.properties
34+
.settings/
35+
.loadpath
36+
.recommenders
37+
38+
# External tool builders
39+
.externalToolBuilders/
40+
41+
# Locally stored "Eclipse launch configurations"
42+
*.launch
43+
44+
# PyDev specific (Python IDE for Eclipse)
45+
*.pydevproject
46+
47+
# CDT-specific (C/C++ Development Tooling)
48+
.cproject
49+
50+
# CDT- autotools
51+
.autotools
52+
53+
# Java annotation processor (APT)
54+
.factorypath
55+
56+
# PDT-specific (PHP Development Tools)
57+
.buildpath
58+
59+
# sbteclipse plugin
60+
.target
61+
62+
# Tern plugin
63+
.tern-project
64+
65+
# TeXlipse plugin
66+
.texlipse
67+
68+
# STS (Spring Tool Suite)
69+
.springBeans
70+
71+
# Code Recommenders
72+
.recommenders/
73+
74+
# Annotation Processing
75+
.apt_generated/
76+
.apt_generated_test/
77+
78+
# Scala IDE specific (Scala & Java development for Eclipse)
79+
.cache-main
80+
.scala_dependencies
81+
.worksheet
82+
83+
# Uncomment this line if you wish to ignore the project description file.
84+
# Typically, this file would be tracked if it contains build/dependency configurations:
85+
#.project
86+
87+
# External tool builders
88+
.externalToolBuilders/
89+
90+
# VS Code - https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
91+
.vscode/*
92+
!.vscode/settings.json
93+
!.vscode/tasks.json
94+
!.vscode/launch.json
95+
!.vscode/extensions.json
96+
!.vscode/*.code-snippets
97+
98+
# Local History for Visual Studio Code
99+
.history/
100+
101+
# Built Visual Studio Code Extensions
102+
*.vsix
103+
104+
# JetBrains .gitignore - https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
105+
# User-specific stuff
106+
.idea/**/workspace.xml
107+
.idea/**/tasks.xml
108+
.idea/**/usage.statistics.xml
109+
.idea/**/dictionaries
110+
.idea/**/shelf
111+
112+
# AWS User-specific
113+
.idea/**/aws.xml
114+
115+
# Generated files
116+
.idea/**/contentModel.xml
117+
118+
# Sensitive or high-churn files
119+
.idea/**/dataSources/
120+
.idea/**/dataSources.ids
121+
.idea/**/dataSources.local.xml
122+
.idea/**/sqlDataSources.xml
123+
.idea/**/dynamic.xml
124+
.idea/**/uiDesigner.xml
125+
.idea/**/dbnavigator.xml
126+
127+
# Gradle
128+
.idea/**/gradle.xml
129+
.idea/**/libraries
130+
131+
# Gradle and Maven with auto-import
132+
# When using Gradle or Maven with auto-import, you should exclude module files,
133+
# since they will be recreated, and may cause churn. Uncomment if using
134+
# auto-import.
135+
# .idea/artifacts
136+
# .idea/compiler.xml
137+
# .idea/jarRepositories.xml
138+
# .idea/modules.xml
139+
# .idea/*.iml
140+
# .idea/modules
141+
# *.iml
142+
# *.ipr
143+
144+
# CMake
145+
cmake-build-*/
146+
147+
# Mongo Explorer plugin
148+
.idea/**/mongoSettings.xml
149+
150+
# File-based project format
151+
*.iws
152+
153+
# IntelliJ
154+
out/
155+
156+
# mpeltonen/sbt-idea plugin
157+
.idea_modules/
158+
159+
# JIRA plugin
160+
atlassian-ide-plugin.xml
161+
162+
# Cursive Clojure plugin
163+
.idea/replstate.xml
164+
165+
# SonarLint plugin
166+
.idea/sonarlint/
167+
168+
# Crashlytics plugin (for Android Studio and IntelliJ)
169+
com_crashlytics_export_strings.xml
170+
crashlytics.properties
171+
crashlytics-build.properties
172+
fabric.properties
173+
174+
# Editor-based Rest Client
175+
.idea/httpRequests
176+
177+
# Android studio 3.1+ serialized cache file
178+
.idea/caches/build_file_checksums.ser
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# jdbc-driver-graalvm-nativeimage
2+
[Introduction to Oracle JDBC Driver Configuration for GraalVM Native Image](https://juarezjunior.medium.com/introduction-to-oracle-jdbc-driver-configuration-for-graalvm-native-image-6130e699d03b)
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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.jdbc.graalvm</groupId>
9+
<artifactId>jdbc-driver-graalvm-nativeimage</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
12+
<name>jdbc-driver-graalvm-nativeimage</name>
13+
<description>Introduction to Oracle JDBC Driver Configuration for GraalVM
14+
Native Image</description>
15+
<url>
16+
https://juarezjunior.medium.com/introduction-to-oracle-jdbc-driver-configuration-for-graalvm-native-image-6130e699d03b</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+
31+
<dependency>
32+
<groupId>org.graalvm.buildtools</groupId>
33+
<artifactId>native-maven-plugin</artifactId>
34+
<version>0.9.28</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.graalvm.nativeimage</groupId>
38+
<artifactId>svm</artifactId>
39+
<version>23.1.1</version>
40+
<scope>provided</scope>
41+
</dependency>
42+
43+
</dependencies>
44+
45+
<build>
46+
<pluginManagement><!-- lock down plugins versions to avoid using Maven
47+
defaults (may be moved to parent pom) -->
48+
<plugins>
49+
<plugin>
50+
<artifactId>maven-clean-plugin</artifactId>
51+
<version>3.1.0</version>
52+
</plugin>
53+
<plugin>
54+
<artifactId>maven-resources-plugin</artifactId>
55+
<version>3.0.2</version>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
<version>3.8.0</version>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-surefire-plugin</artifactId>
63+
<version>2.22.1</version>
64+
</plugin>
65+
66+
<plugin>
67+
<artifactId>maven-jar-plugin</artifactId>
68+
<version>3.0.2</version>
69+
<configuration>
70+
<archive>
71+
<manifest>
72+
<mainClass>
73+
com.oracle.jdbc.graalvm.GraalVMNativeImageJDBCDriver</mainClass>
74+
</manifest>
75+
</archive>
76+
</configuration>
77+
</plugin>
78+
79+
<plugin>
80+
<artifactId>maven-install-plugin</artifactId>
81+
<version>2.5.2</version>
82+
</plugin>
83+
<plugin>
84+
<artifactId>maven-deploy-plugin</artifactId>
85+
<version>2.8.2</version>
86+
</plugin>
87+
88+
</plugins>
89+
</pluginManagement>
90+
</build>
91+
92+
<profiles>
93+
<profile>
94+
<id>native</id>
95+
<build>
96+
<plugins>
97+
<plugin>
98+
<groupId>org.graalvm.buildtools</groupId>
99+
<artifactId>native-maven-plugin</artifactId>
100+
<version>0.9.28</version>
101+
<extensions>true</extensions>
102+
<executions>
103+
<execution>
104+
<id>build-native</id>
105+
<goals>
106+
<goal>compile-no-fork</goal>
107+
</goals>
108+
<phase>package</phase>
109+
</execution>
110+
<execution>
111+
<id>test-native</id>
112+
<goals>
113+
<goal>test</goal>
114+
</goals>
115+
<phase>test</phase>
116+
</execution>
117+
</executions>
118+
119+
<configuration>
120+
<fallback>true</fallback>
121+
<buildArgs>
122+
<arg>-H:DashboardDump=jdbc-driver-graalvm-nativeimage
123+
-H:+DashboardAll</arg>
124+
<arg>-H:+DashboardAll</arg>
125+
</buildArgs>
126+
<agent>
127+
<enabled>true</enabled>
128+
</agent>
129+
</configuration>
130+
131+
</plugin>
132+
</plugins>
133+
</build>
134+
</profile>
135+
</profiles>
136+
137+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.jdbc.graalvm;
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 GraalVMNativeImageJDBCDriver {
32+
33+
public static void main(String[] args) throws SQLException {
34+
OracleDataSource ods = new OracleDataSource();
35+
// jdbc:oracle:thin@[hostname]:[port]/[DB service/name]
36+
ods.setURL("jdbc:oracle:thin@[hostname]:[port]/[DB service/name]");
37+
ods.setUser("[Username]");
38+
ods.setPassword("[Password]");
39+
40+
try (Connection conn = ods.getConnection();
41+
PreparedStatement stmt = conn
42+
.prepareStatement("SELECT 'Hello World!' FROM dual");
43+
ResultSet rslt = stmt.executeQuery();) {
44+
while (rslt.next()) {
45+
System.out.println(rslt.getString(1));
46+
}
47+
} catch (SQLException e) {
48+
e.printStackTrace();
49+
}
50+
}
51+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /