cleanup db access
This commit is contained in:
parent
69cb4417fd
commit
7f0800cf52
1
connection_string.txt
Normal file
1
connection_string.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
jdbc:postgresql://localhost:5432/mydb?user=postgres&password=postgres
|
||||||
@ -6,6 +6,9 @@ import lombok.NonNull;
|
|||||||
import lombok.Singular;
|
import lombok.Singular;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
@ -14,7 +17,15 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
public final class DbQuery {
|
public final class DbQuery {
|
||||||
private static final String connectionString = "jdbc:postgresql://localhost:5432/mydb?user=postgres&password=postgres";
|
private static final String connectionString;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
connectionString = Files.readString(Paths.get("connection_string.txt"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final SqlCommand command;
|
private final SqlCommand command;
|
||||||
@ -143,8 +154,6 @@ public final class DbQuery {
|
|||||||
}
|
}
|
||||||
statementExecutor.setObject(i++, value);
|
statementExecutor.setObject(i++, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(sql);
|
|
||||||
return statementExecutor.executeUpdate();
|
return statementExecutor.executeUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,8 +180,6 @@ public final class DbQuery {
|
|||||||
}
|
}
|
||||||
statementExecutor.setObject(i++, value);
|
statementExecutor.setObject(i++, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(sql);
|
|
||||||
return statementExecutor.execute();
|
return statementExecutor.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,7 +207,6 @@ public final class DbQuery {
|
|||||||
statementExecutor.setObject(i++, value);
|
statementExecutor.setObject(i++, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(sql);
|
|
||||||
try (ResultSet resultSet = statementExecutor.executeQuery()) {
|
try (ResultSet resultSet = statementExecutor.executeQuery()) {
|
||||||
|
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
List<Map<String, Object>> result = new ArrayList<>();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user