Java SQL Type mapType(Class javaType)

Here you can find the source of mapType(Class javaType)

Description

Map a Java type to a SQL type.

License

Apache License

Declaration

private static String mapType(Class javaType) throws Exception 

Method Source Code

//package com.java2s;
/*/* www. j a v a2  s.c  om*/

 Derby - Class org.apache.derbyDemo.vtis.core.VTIHelper

 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.math.BigDecimal;
import java.sql.*;

public class Main {
    /**
     * <p>
     * Map a Java type to a SQL type.
     * </p>
     */
    private static String mapType(Class javaType) throws Exception {
        if (javaType == Long.class) {
            return "bigint";
        } else if (javaType == Blob.class) {
            return "blob";
        } else if (javaType == String.class) {
            return "varchar( 32672 )";
        } else if (javaType == Clob.class) {
            return "clob";
        } else if (javaType == BigDecimal.class) {
            return "decimal";
        } else if (javaType == Double.class) {
            return "double";
        } else if (javaType == Float.class) {
            return "float";
        } else if (javaType == Integer.class) {
            return "integer";
        } else if (javaType == byte[].class) {
            return "long varchar for bit data";
        } else if (javaType == Short.class) {
            return "smallint";
        } else if (javaType == Timestamp.class) {
            return "timestamp";
        } else {
            throw new Exception(
                    "Unsupported type of argument to Table Function: "
                            + javaType.getName());
        }
    }
}

Related

  1. jdbcTypeToKylinDataType(int sqlType)
  2. listToJson(List list)
  3. loadAllTypesData(Connection conn)
  4. loadTestDataForEveryType(Connection conn)
  5. mapECLtype2SQLtype(String ecltype)
  6. mapXSDTypeName2SQLtype(String xsdtype)
  7. marshalCurlType(String javaType, boolean isAllowNull, boolean generateGenerics)
  8. matchMethods(String name, Method[] methods, Class[] spt, int mrs, boolean exact)
  9. nativeSQL(String sql, boolean noBackslashEscapes)

  10. HOME | Copyright © www.java2s.com 2016