Skip to content

Instantly share code, notes, and snippets.

@bryanchug
Created November 5, 2013 03:10
Show Gist options
  • Save bryanchug/7313238 to your computer and use it in GitHub Desktop.
Save bryanchug/7313238 to your computer and use it in GitHub Desktop.
Passing in default timezone to MySQL connection via JDBC URL
@Grab(group='mysql', module='mysql-connector-java', version='5.1.6')
@GrabConfig(systemClassLoader = true)
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/noonu?sessionVariables=time_zone='-8:00'", 'root', '', 'com.mysql.jdbc.Driver')
println sql.firstRow("select now()")
def sql2 = Sql.newInstance("jdbc:mysql://localhost:3306/noonu?sessionVariables=time_zone='%2B8:00'", 'root', '', 'com.mysql.jdbc.Driver')
println sql2.firstRow("select now()")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment