Java SQL Time From getDateTimeTypeString(Connection conn)

Here you can find the source of getDateTimeTypeString(Connection conn)

Description

get Date Time Type String

License

Open Source License

Declaration

public static String getDateTimeTypeString(Connection conn) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 *
 * This file is part of Weave.//  w  w  w  . ja  v a 2s  .  c  om
 *
 * The Initial Developer of Weave is the Institute for Visualization
 * and Perception Research at the University of Massachusetts Lowell.
 * Portions created by the Initial Developer are Copyright (C) 2008-2015
 * the Initial Developer. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * ***** END LICENSE BLOCK ***** */

import java.sql.Connection;

import java.sql.SQLException;

public class Main {
    public static String MYSQL = "MySQL";
    public static String SQLITE = "SQLite";
    public static String POSTGRESQL = "PostgreSQL";
    public static String SQLSERVER = "Microsoft SQL Server";
    public static String ORACLE = "Oracle";

    public static String getDateTimeTypeString(Connection conn) {
        if (isOracleServer(conn))
            return "DATE";
        return "DATETIME";
    }

    /**
     * This function checks if a connection is for an Oracle server.
     * @param conn A SQL Connection.
     * @return A value of true if the Connection is for an Oracle server.
     * @throws SQLException 
     */
    public static boolean isOracleServer(Connection conn) {
        return getDbmsFromConnection(conn).equals(ORACLE);
    }

    public static String getDbmsFromConnection(Connection conn) {
        try {
            String dbms = conn.getMetaData().getDatabaseProductName();
            for (String match : new String[] { ORACLE, SQLSERVER, MYSQL,
                    SQLITE, POSTGRESQL })
                if (dbms.equalsIgnoreCase(match))
                    return match;
            return dbms;
        } catch (SQLException e) {
            return "";
        }
    }
}

Related

  1. getDateTimeStr(Date date)
  2. getDateTimeString(java.sql.Date dd)
  3. getDateTimeString(String format)
  4. getDateTimeStringFromCalendar(Calendar calendar)
  5. getDateTimeTypeString(Connection conn)
  6. toDateTime(final java.util.Date d)
  7. toDatetime(long value)
  8. toDateTimeString(java.util.Date inDate)
  9. toSQLTime(final LocalTime lt)