forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHikariApp.java
More file actions
41 lines (35 loc) · 1.02 KB
/
Copy pathHikariApp.java
File metadata and controls
41 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package examples;
import io.jooby.Jooby;
import io.jooby.hikari.HikariModule;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
public class HikariApp extends Jooby {
{
install(new HikariModule("jdbc:mysql://localhost/hello?user=root&password="));
get("/", ctx -> {
try (Connection connection = require(DataSource.class).getConnection()) {
try (PreparedStatement stt = connection.prepareStatement("select * from users")) {
try (ResultSet rs = stt.executeQuery()) {
List<String> names = new ArrayList<>();
while (rs.next()) {
names.add(rs.getString(1));
}
return names;
}
}
}
});
}
public static void main(String[] args) {
runApp(args, HikariApp::new);
}
}