1/24/2020

Mysql and the Groovysh

I wanted to use mysql in groovy shell, and I found it a bit trickier than usual. Also there is literally nothing covering how to do this on the internet. First thing is to configure your graphConfig.xml file. Edit your grapeConfig.xml file (for *nix ~/.groovy/grapeConfig.xml). Then drop your config in there: I had to update mine because I guess the central repo changed to requiring https now. Fire up the groovy shell. Then execute this command:

groovy:000> :grab 'mysql:mysql-connector-java:8.0.18'

Now here is where things get a little weird:

groovy:000> sql = Sql.newInstance('jdbc:mysql://localhost:3306/someDB', 
    'person', 
    'none of your business!')
ERROR java.sql.SQLException:
No suitable driver found for jdbc:mysql://localhost:3306/someDB

So that sucks. Unfortunately the driver isn't known to the DriverManager so no workie. Too close for missiles, switching to guns for this one:

groovy:000> sql = Sql.newInstance('jdbc:mysql://localhost:3306/someDB', 
    'person', 
    'none of your business!', 
    "com.mysql.cj.jdbc.Driver")

Bam! Now we're ready to start slamming some SQL in groovysh (woot).