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