CacheManager cacheManager = new CacheManager();
Cache cache = cacheManager.getCache("employeeCache");
String sql = "SELECT * FROM employees";
try (Connection connection = DriverManager.getConnection(url, user, password);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql)) {
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
Employee employee = new Employee(id, name);
cache.put(id, employee);
}
Employee employee = cache.get(1);
System.out.println(employee.getName());
} catch (SQLException e) {
e.printStackTrace();
}
DataSourceConfig config = new DataSourceConfig();
config.setMinConnections(5);
config.setMaxConnections(20);
config.setUsername(user);
config.setPassword(password);
config.setUrl(url);
ConnectionPool pool = new ConnectionPool(config);
try (Connection connection = pool.getConnection()) {
// ...
} catch (SQLException e) {
e.printStackTrace();
}