Java SQL Type getTinyIntTypeString(Connection conn)

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

Description

get Tiny Int Type String

License

Open Source License

Declaration

public static String getTinyIntTypeString(Connection conn)
            throws SQLException 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 *
 * This file is part of Weave./*from   w  w w.j av a  2s  .  co 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 getTinyIntTypeString(Connection conn)
            throws SQLException {
        String dbms = getDbmsFromConnection(conn);
        if (dbms.equals(ORACLE))
            return "NUMBER(1,0)";
        if (dbms.equals(POSTGRESQL))
            return "SMALLINT";

        // mysql, sqlserver
        return "TINYINT";
    }

    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. getSQLTypePrecision(int sqlType)
  2. getSQLTypeRadix(int sqlType)
  3. getSqlValue(Object o)
  4. getStringFormat(int colType)
  5. getTableTypes(DatabaseMetaData dbmd)
  6. getType(int csqltype)
  7. getTypeforValue(int type)
  8. getTypeName(int dataType)
  9. getTypeName(int typeNumber)