Skip to content

Commit 62a2c03

Browse files
committed
Java: Reorganize section
1 parent 595c200 commit 62a2c03

File tree

9 files changed

+345
-248
lines changed

9 files changed

+345
-248
lines changed

docs/connect/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ application
176176
:maxdepth: 1
177177
:hidden:
178178
179-
java
179+
java/index
180180
javascript
181181
php
182182
python

docs/connect/java.md

Lines changed: 0 additions & 247 deletions
This file was deleted.

docs/connect/java/_jdbc_example.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
orphan: true
3+
---
4+
:::{card}
5+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/java-jdbc
6+
:link-type: url
7+
:width: 50%
8+
{material-regular}`play_arrow;2em`
9+
Connect to CrateDB using JDBC
10+
+++
11+
Demonstrates a basic example using both the vanilla PostgreSQL JDBC Driver
12+
and the CrateDB JDBC Driver.
13+
:::

docs/connect/java/cratedb-jdbc.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
(crate-jdbc)=
2+
(cratedb-jdbc)=
3+
4+
# CrateDB JDBC
5+
6+
:::{rubric} Synopsis
7+
:::
8+
9+
```java
10+
Properties properties = new Properties();
11+
properties.put("user", "admin");
12+
properties.put("password", "<PASSWORD>");
13+
properties.put("ssl", true);
14+
Connection conn = DriverManager.getConnection(
15+
"jdbc:crate://<name-of-your-cluster>.cratedb.net:5432/",
16+
properties
17+
);
18+
```
19+
20+
:::{rubric} Maven
21+
:::
22+
23+
```xml
24+
<dependencies>
25+
<dependency>
26+
<groupId>io.crate</groupId>
27+
<artifactId>crate-jdbc</artifactId>
28+
<version>2.7.0</version>
29+
</dependency>
30+
</dependencies>
31+
```
32+
33+
:::{rubric} Gradle
34+
:::
35+
36+
```groovy
37+
repositories {
38+
mavenCentral()
39+
}
40+
dependencies {
41+
implementation 'io.crate:crate-jdbc:2.7.0'
42+
}
43+
```
44+
45+
:::{rubric} Download
46+
:::
47+
48+
:::{card}
49+
:link: https://cratedb.com/docs/jdbc/en/latest/getting-started.html#installation
50+
:link-type: url
51+
{material-regular}`download;2em`
52+
Download and install the CrateDB JDBC Driver
53+
:::
54+
55+
:::{rubric} Full example
56+
:::
57+
58+
:::{dropdown} `main.java`
59+
```java
60+
import java.sql.*;
61+
import java.util.Properties;
62+
63+
public class Main {
64+
public static void main(String[] args) {
65+
try {
66+
Properties properties = new Properties();
67+
properties.put("user", "admin");
68+
properties.put("password", "<PASSWORD>");
69+
properties.put("ssl", true);
70+
Connection conn = DriverManager.getConnection(
71+
"jdbc:crate://<name-of-your-cluster>.cratedb.net:5432/",
72+
properties
73+
);
74+
75+
Statement statement = conn.createStatement();
76+
ResultSet resultSet = statement.executeQuery("SELECT name FROM sys.cluster");
77+
resultSet.next();
78+
String name = resultSet.getString("name");
79+
80+
System.out.println(name);
81+
} catch (SQLException e) {
82+
e.printStackTrace();
83+
}
84+
}
85+
}
86+
```
87+
:::
88+
89+
90+
## JDBC example
91+
92+
:::{include} _jdbc_example.md
93+
:::
94+
95+
96+
[![Java: JDBC, QA](https://github.com/crate/cratedb-examples/actions/workflows/lang-java-maven.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-java-maven.yml)

docs/connect/java/hibernate.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(jpa)=
2+
(hibernate)=
3+
(panache)=
4+
(quarkus)=
5+
6+
# Hibernate / JPA
7+
8+
:::{include} /_include/links.md
9+
:::
10+
11+
:::{div}
12+
[Hibernate] is the top dog ORM for Java, supporting a range of databases,
13+
including PostgreSQL. [JPA], or Jakarta Persistence API (formerly Java
14+
Persistence API), is a Java specification that simplifies the process of
15+
mapping Java objects to relational databases.
16+
:::
17+
18+
:::{card}
19+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/java-quarkus-panache
20+
:link-type: url
21+
:width: 50%
22+
{material-regular}`play_arrow;2em`
23+
Connect to CrateDB using JPA and Panache
24+
+++
25+
How CrateDB can be utilized with Quarkus in a very intuitive way
26+
using the Hibernate ORM deriving from PostgreSQL.
27+
:::

0 commit comments

Comments
 (0)