TimezoneDump.java
上传用户:sxlinghang
上传日期:2022-07-20
资源大小:1405k
文件大小:2k
源码类别:

数据库编程

开发平台:

Java

  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. import java.sql.DriverManager;
  22. import java.sql.ResultSet;
  23. import com.mysql.jdbc.TimeUtil;
  24. /**
  25.  * Dumps the timezone of the MySQL server represented by the 
  26.  * JDBC url given on the commandline (or localhost/test if 
  27.  * none provided).
  28.  * 
  29.  * @author Mark Matthews
  30.  */
  31. public class TimezoneDump {
  32.     private static final String DEFAULT_URL = "jdbc:mysql:///test";
  33.     
  34. /**
  35.  * Constructor for TimezoneDump.
  36.  */
  37. public TimezoneDump() {
  38. super();
  39. }
  40.     /**
  41.      * Entry point for program when called from the command line.
  42.      * 
  43.      * @param args command-line args. Arg 1 is JDBC URL.
  44.      * @throws Exception if any errors occur
  45.      */
  46. public static void main(String[] args) throws Exception {
  47.         String jdbcUrl = DEFAULT_URL;
  48.         
  49.         if (args.length == 1 && args[0] != null) {
  50.             jdbcUrl = args[0];
  51.         }
  52.         
  53.         Class.forName("com.mysql.jdbc.Driver").newInstance();
  54.         ResultSet rs = DriverManager.getConnection(jdbcUrl).createStatement().executeQuery("SHOW VARIABLES LIKE 'timezone'");
  55.         
  56.         while (rs.next()) {
  57.             String timezoneFromServer = rs.getString(2);
  58.             System.out.println("MySQL timezone name: " + timezoneFromServer);
  59.             
  60.             String canonicalTimezone = TimeUtil.getCanoncialTimezone(timezoneFromServer);
  61.             System.out.println("Java timezone name: " + canonicalTimezone);
  62.         }
  63.         
  64. }
  65. }