KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mysql > jdbc > util > TimezoneDump


1 /*
2    Copyright (C) 2002 MySQL AB
3    
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8    
9       This program is distributed in the hope that it will be useful,
10       but WITHOUT ANY WARRANTY; without even the implied warranty of
11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12       GNU General Public License for more details.
13    
14       You should have received a copy of the GNU General Public License
15       along with this program; if not, write to the Free Software
16       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17       
18  */

19  
20 package com.mysql.jdbc.util;
21
22 import java.sql.DriverManager JavaDoc;
23 import java.sql.ResultSet JavaDoc;
24
25 import com.mysql.jdbc.TimeUtil;
26
27 /**
28  * Dumps the timezone of the MySQL server represented by the
29  * JDBC url given on the commandline (or localhost/test if
30  * none provided).
31  *
32  * @author Mark Matthews
33  */

34 public class TimezoneDump {
35
36     private static final String JavaDoc DEFAULT_URL = "jdbc:mysql:///test";
37     
38     /**
39      * Constructor for TimezoneDump.
40      */

41     public TimezoneDump() {
42         super();
43     }
44
45     /**
46      * Entry point for program when called from the command line.
47      *
48      * @param args command-line args. Arg 1 is JDBC URL.
49      * @throws Exception if any errors occur
50      */

51     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
52         String JavaDoc 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 JavaDoc rs = DriverManager.getConnection(jdbcUrl).createStatement().executeQuery("SHOW VARIABLES LIKE 'timezone'");
60         
61         while (rs.next()) {
62             String JavaDoc timezoneFromServer = rs.getString(2);
63             System.out.println("MySQL timezone name: " + timezoneFromServer);
64             
65             String JavaDoc canonicalTimezone = TimeUtil.getCanoncialTimezone(timezoneFromServer);
66             System.out.println("Java timezone name: " + canonicalTimezone);
67         }
68         
69     }
70 }
71
Popular Tags