Java SQL Type getVarcharTypeString(Connection conn, int length)

Here you can find the source of getVarcharTypeString(Connection conn, int length)

Description

get Varchar Type String

License

Open Source License

Declaration

public static String getVarcharTypeString(Connection conn, int length) 

Method Source Code

//package com.java2s;
/*/*from  ww  w. j  a  v a 2 s  .  c  om*/
Weave (Web-based Analysis and Visualization Environment)
Copyright (C) 2008-2011 University of Massachusetts Lowell
    
This file is a part of Weave.
    
Weave is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License, Version 3,
as published by the Free Software Foundation.
    
Weave is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.sql.Connection;

import java.sql.SQLException;

public class Main {
    public static String ORACLE = "Oracle";

    public static String getVarcharTypeString(Connection conn, int length) {
        if (isOracleServer(conn))
            return String.format("VARCHAR2(%s)", length);
        return String.format("VARCHAR(%s)", length);
    }

    /**
     * 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.
     */
    public static boolean isOracleServer(Connection conn) {
        try {
            if (conn.getMetaData().getDatabaseProductName().equalsIgnoreCase(ORACLE))
                return true;
        } catch (SQLException e) // This is expected to be thrown if the connection is invalid.
        {
            e.printStackTrace();
        } catch (RuntimeException e) // This is important for catching unexpected errors.
        {
            return false;
        }

        return false;
    }
}

Related

  1. getTypeName(int typeNumber)
  2. getTypeNameForJDBCType(int jdbcType)
  3. getTypeStringForObject(Object o)
  4. getUDTOwner(String typeName, String dbName, Connection conn)
  5. getValueType(String inputValue)
  6. getViewIdsForTypes(Connection connection, String... types)
  7. indexOf(Object[] array, Object objectToFind)
  8. invokeJdbcMethod(Class interfaceClass, String methodName, Class[] argTypes, Object target, Object[] args)
  9. isBinary(int dataType)