-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
per
committed
Jul 15, 2022
1 parent
b4f9777
commit 1229b9c
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
# data-utils | ||
Groovy data utils | ||
Groovy data utils. The main issue I needed to address was the reliance on System classloader in @Grab to handle JDBC drivers. | ||
This is very inconvenient when using an IDE such as [Gride](/perNyfelt/gride) as it requires you to copy jars to the Gride lib folder and | ||
restart the IDE in order for the System classpath to be updated. | ||
|
||
However, with some Reflection magic it is possible to do without this. This is what se.alipsa.groovy.datautil.SqlUtil does. | ||
|
||
Here is an example: | ||
|
||
```groovy | ||
@Grab('se.alipsa.groovy:data-utils:1.0.0') | ||
@Grab('org.postgresql:postgresql:42.4.0') | ||
import se.alipsa.groovy.datautil.SqlUtil | ||
def idList = new ArrayList() | ||
SqlUtil.withInstance("jdbc:postgresql://localhost:5432/mydb", "dbUser", "dbPasswd", "org.postgresql.Driver") { sql -> | ||
sql.query('SELECT id FROM project') { rs -> | ||
while (rs.next()) { | ||
idList.add(rs.getLong(1)) | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters