01: /*
02: Copyright (C) 2002-2004 MySQL AB
03:
04: This program is free software; you can redistribute it and/or modify
05: it under the terms of version 2 of the GNU General Public License as
06: published by the Free Software Foundation.
07:
08: There are special exceptions to the terms and conditions of the GPL
09: as it is applied to this software. View the full text of the
10: exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11: software distribution.
12:
13: This program is distributed in the hope that it will be useful,
14: but WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: GNU General Public License for more details.
17:
18: You should have received a copy of the GNU General Public License
19: along with this program; if not, write to the Free Software
20: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21:
22:
23:
24: */
25: package com.mysql.jdbc.util;
26:
27: import com.mysql.jdbc.TimeUtil;
28:
29: import java.sql.DriverManager;
30: import java.sql.ResultSet;
31:
32: /**
33: * Dumps the timezone of the MySQL server represented by the JDBC url given on
34: * the commandline (or localhost/test if none provided).
35: *
36: * @author Mark Matthews
37: */
38: public class TimezoneDump {
39: // ~ Static fields/initializers
40: // ---------------------------------------------
41:
42: private static final String DEFAULT_URL = "jdbc:mysql:///test";
43:
44: // ~ Constructors
45: // -----------------------------------------------------------
46:
47: /**
48: * Constructor for TimezoneDump.
49: */
50: public TimezoneDump() {
51: super ();
52: }
53:
54: // ~ Methods
55: // ----------------------------------------------------------------
56:
57: /**
58: * Entry point for program when called from the command line.
59: *
60: * @param args
61: * command-line args. Arg 1 is JDBC URL.
62: * @throws Exception
63: * if any errors occur
64: */
65: public static void main(String[] args) throws Exception {
66: String jdbcUrl = DEFAULT_URL;
67:
68: if ((args.length == 1) && (args[0] != null)) {
69: jdbcUrl = args[0];
70: }
71:
72: Class.forName("com.mysql.jdbc.Driver").newInstance();
73:
74: ResultSet rs = DriverManager.getConnection(jdbcUrl)
75: .createStatement().executeQuery(
76: "SHOW VARIABLES LIKE 'timezone'");
77:
78: while (rs.next()) {
79: String timezoneFromServer = rs.getString(2);
80: System.out.println("MySQL timezone name: "
81: + timezoneFromServer);
82:
83: String canonicalTimezone = TimeUtil
84: .getCanoncialTimezone(timezoneFromServer);
85: System.out.println("Java timezone name: "
86: + canonicalTimezone);
87: }
88: }
89: }
|