Skip to content

Instantly share code, notes, and snippets.

@aalmiray

aalmiray/TodoResource.java

Last active May 19, 2020
Embed
What would you like to do?
Quarkus + Oracle JDBC
quarkus.datasource.todos.db-kind=other
quarkus.datasource.todos.jdbc.driver=oracle.jdbc.driver.OracleDriver
quarkus.datasource.todos.jdbc.url=jdbc:oracle:thin:@localhost:1521/XEPDB1
quarkus.datasource.todos.username=system
quarkus.datasource.todos.password=R4nd0mP@$$woRd
dependencies {
implementation enforcedPlatform('io.quarkus:quarkus-universe-bom:1.4.2.Final')
implementation 'com.oracle.database.jdbc:ojdbc8:19.6.0.0'
implementation 'io.quarkus:quarkus-agroal'
}
<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.6.0.0</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
</dependencies>
package com.acme;
import io.agroal.api.AgroalDataSource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@Path("/todos")
public class TodoResource {
@Inject
@Named("todos")
AgroalDataSource dataSource;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() throws SQLException {
StringBuilder sb = new StringBuilder();
try (Connection connection = dataSource.getConnection();
PreparedStatement ps =
connection.prepareStatement(" SELECT * FROM todos");
ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
sb.append(rs.getString("description")).append("\n");
}
}
return sb.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.