Skip to content

Commit 2b36df1

Browse files
committed
closing connection to database after done with operation
1 parent 050aa11 commit 2b36df1

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

samples/mysql-schema/src/main/java/com/github/containersolutions/operator/sample/SchemaController.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public class SchemaController implements ResourceController<Schema> {
2323

2424
@Override
2525
public Optional<Schema> createOrUpdateResource(Schema schema) {
26-
try {
27-
Connection connection = getConnection();
26+
try (Connection connection = getConnection()) {
2827
ResultSet resultSet = connection.createStatement().executeQuery(
2928
format("SELECT schema_name FROM information_schema.schemata WHERE schema_name = \"%1$s\"",
3029
schema.getMetadata().getName()));
@@ -61,8 +60,7 @@ public Optional<Schema> createOrUpdateResource(Schema schema) {
6160
public boolean deleteResource(Schema schema) {
6261
log.info("Execution deleteResource for: {}", schema.getMetadata().getName());
6362

64-
try {
65-
Connection connection = getConnection();
63+
try (Connection connection = getConnection()) {
6664
connection.createStatement().execute("DROP DATABASE `" + schema.getMetadata().getName() + "`");
6765
log.info("Deleted Schema '{}'", schema.getMetadata().getName());
6866

0 commit comments

Comments
 (0)