Java SQL Type getDoubleTypeString(Connection conn)

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

Description

get Double Type String

License

Open Source License

Declaration

public static String getDoubleTypeString(Connection conn) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 *
 * This file is part of Weave./*from w  w w .  j a  v a 2s  .c o  m*/
 *
 * 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 getDoubleTypeString(Connection conn) {
        if (isSQLServer(conn))
            return "FLOAT"; // this is an 8 floating point type with 53 bits for the mantissa, the same as an 8 byte double.
                            // but SQL Server's DOUBLE PRECISION type isn't standard
        return "DOUBLE PRECISION";
    }

    /**
     * This function checks if a connection is for a Microsoft SQL Server.
     * @param conn A SQL Connection.
     * @return A value of true if the Connection is for a Microsoft SQL Server.
     */
    public static boolean isSQLServer(Connection conn) {
        return getDbmsFromConnection(conn).equals(SQLSERVER);
    }

    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. getDbDataType(Object o)
  2. getDefaultPrecision(int sqlType)
  3. getDefaultScale(int sqlType)
  4. getDefaultValue(Class type)
  5. getDoubleTypeString(Connection conn)
  6. getExpressionChoices(int type)
  7. getFormatTypeAsString(int fieldType)
  8. getInsertarEmpresa()
  9. getIntTypeString(Connection conn)