Java SQL Type columnPrecision(int columnType)

Here you can find the source of columnPrecision(int columnType)

Description

Column precision.

License

Apache License

Parameter

Parameter Description
columnType the column type

Exception

Parameter Description
SQLException the SQL exception

Return

the int

Declaration

static int columnPrecision(int columnType) throws SQLException 

Method Source Code

//package com.java2s;
/**//from www. ja v  a 2  s .com
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.sql.SQLException;

import java.sql.Types;

public class Main {
    /**
     * Column precision.
     *
     * @param columnType the column type
     * @return the int
     * @throws SQLException the SQL exception
     */
    static int columnPrecision(int columnType) throws SQLException {
        // according to hiveTypeToSqlType possible options are:
        switch (columnType) {
        case Types.BOOLEAN:
            return 1;
        case Types.CHAR:
        case Types.VARCHAR:
            return Integer.MAX_VALUE; // hive has no max limit for strings
        case Types.BINARY:
            return Integer.MAX_VALUE; // hive has no max limit for binary
        case Types.TINYINT:
            return 3;
        case Types.SMALLINT:
            return 5;
        case Types.INTEGER:
            return 10;
        case Types.BIGINT:
            return 19;
        case Types.FLOAT:
            return 7;
        case Types.DOUBLE:
            return 15;
        case Types.DATE:
            return 10;
        case Types.TIMESTAMP:
            return 29;
        case Types.DECIMAL:
            return 5;
        case Types.JAVA_OBJECT:
        case Types.ARRAY:
        case Types.STRUCT:
            return Integer.MAX_VALUE;
        default:
            throw new SQLException("Invalid column type: " + columnType);
        }
    }
}

Related

  1. addParameter(PreparedStatement smt, int index, Object value)
  2. adjustLevel(String attribute, int type)
  3. callPro2(String sql, String[] inparameters, Integer[] outparameters)
  4. columnClassName(int columnType)
  5. columnDisplaySize(int columnType)
  6. columnScale(int columnType)
  7. columnTypesDiffer(int t1, int t2)
  8. compressType(int type)
  9. convert2MysqlType(String cls)