1 19 20 package com.mysql.jdbc.util; 21 22 import java.sql.DriverManager ; 23 import java.sql.ResultSet ; 24 25 import com.mysql.jdbc.TimeUtil; 26 27 34 public class TimezoneDump { 35 36 private static final String DEFAULT_URL = "jdbc:mysql:///test"; 37 38 41 public TimezoneDump() { 42 super(); 43 } 44 45 51 public static void main(String [] args) throws Exception { 52 String jdbcUrl = DEFAULT_URL; 53 54 if (args.length == 1 && args[0] != null) { 55 jdbcUrl = args[0]; 56 } 57 58 Class.forName("com.mysql.jdbc.Driver").newInstance(); 59 ResultSet rs = DriverManager.getConnection(jdbcUrl).createStatement().executeQuery("SHOW VARIABLES LIKE 'timezone'"); 60 61 while (rs.next()) { 62 String timezoneFromServer = rs.getString(2); 63 System.out.println("MySQL timezone name: " + timezoneFromServer); 64 65 String canonicalTimezone = TimeUtil.getCanoncialTimezone(timezoneFromServer); 66 System.out.println("Java timezone name: " + canonicalTimezone); 67 } 68 69 } 70 } 71 | Popular Tags |