Skip to content

Commit e85177b

Browse files
committed
SqlExecutor BASH
1 parent 89fee8a commit e85177b

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

mvnw renamed to mvnw.sh

File renamed without changes.

src/main/java/net/ponec/script/SqlExecutor.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static void main(final String[] args) throws Exception {
3232

3333
void mainStart(Connection dbConnection) throws Exception {
3434
try (SqlParamBuilder builder = new SqlParamBuilder(dbConnection)) {
35-
// CREATE TABLE:
35+
System.out.println("# CREATE TABLE");
3636
builder.sql("""
3737
CREATE TABLE employee
3838
( id INTEGER PRIMARY KEY
@@ -42,7 +42,7 @@ void mainStart(Connection dbConnection) throws Exception {
4242
)""")
4343
.execute();
4444

45-
// SINGLE INSERT:
45+
System.out.println("# SINGLE INSERT");
4646
builder.sql("""
4747
INSERT INTO employee
4848
( id, code, created ) VALUES
@@ -53,7 +53,7 @@ void mainStart(Connection dbConnection) throws Exception {
5353
.bind("created", someDate)
5454
.execute();
5555

56-
// MULTI INSERT:
56+
System.out.println("# MULTI INSERT");
5757
builder.sql("""
5858
INSERT INTO employee
5959
(id,code,created) VALUES
@@ -63,14 +63,14 @@ void mainStart(Connection dbConnection) throws Exception {
6363
.bind("id1", 2)
6464
.bind("id2", 3)
6565
.bind("code", "T")
66-
.bind("created", someDate.plusDays(1))
66+
.bind("created", someDate.plusDays(7))
6767
.execute();
6868
builder.bind("id1", 11)
6969
.bind("id2", 12)
7070
.bind("code", "V")
7171
.execute();
7272

73-
// SELECT 1:
73+
System.out.println("# SELECT");
7474
List<Employee> employees = builder.sql("""
7575
SELECT t.id, t.name, t.created
7676
FROM employee t
@@ -91,7 +91,7 @@ AND t.code IN (:code)
9191
assertEquals("test", employees.get(0).name);
9292
assertEquals(someDate, employees.get(0).created);
9393

94-
// REUSE THE SELECT:
94+
System.out.println("# REUSE THE SELECT\n");
9595
List<Employee> employees2 = builder
9696
.bind("id", 100)
9797
.streamMap(rs -> new Employee(
@@ -100,6 +100,7 @@ AND t.code IN (:code)
100100
rs.getObject(3, LocalDate.class)))
101101
.toList();
102102
assertEquals(5, employees2.size());
103+
employees2.stream().forEach(System.out::println);
103104
}
104105
}
105106

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/bin/bash
22
# Sample SQL scripting for the Bash and Java v17.
33

4-
java -cp ../lib/h2-2.2.224.jar SqlExecutor.java "$@"
4+
set -e
5+
cd $(dirname $0)
6+
version=2.2.224
7+
driver=$HOME/.m2/repository/com/h2database/h2/$version/h2-$version.jar
8+
mvn=../../../../../../mvnw.sh
59

10+
if [ ! -e "$driver" ]; then
11+
sh $mvn dependency:get -Dartifact=com.h2database:h2:$version
12+
fi
613

14+
java -cp $driver SqlExecutor.java "$@"

0 commit comments

Comments
 (0)