Here you can find the source of getColumnType(ResultSetMetaData rsmd, int idx)
Get the type of an external database's column as a Derby type name.
private static String getColumnType(ResultSetMetaData rsmd, int idx) throws SQLException
//package com.java2s; /*//from w w w .j a v a 2s .c o m Derby - Class org.apache.derbyDemo.vtis.core.QueryVTIHelper 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.*; public class Main { /** * <p> * Get the type of an external database's column as a Derby type name. * </p> * */ private static String getColumnType(ResultSetMetaData rsmd, int idx) throws SQLException { int jdbcType = rsmd.getColumnType(idx); int precision = rsmd.getPrecision(idx); int scale = rsmd.getScale(idx); switch (jdbcType) { case Types.BIGINT: return "bigint"; case Types.BINARY: return "char " + precisionToLength(precision) + " for bit data"; case Types.BIT: return "smallint"; case Types.BLOB: return "blob"; case Types.BOOLEAN: return "smallint"; case Types.CHAR: return "char" + precisionToLength(precision); case Types.CLOB: return "clob"; case Types.DATE: return "date"; case Types.DECIMAL: return "decimal" + precisionAndScale(precision, scale); case Types.DOUBLE: return "double"; case Types.FLOAT: return "float"; case Types.INTEGER: return "integer"; case Types.LONGVARBINARY: return "long varchar for bit data"; case Types.LONGVARCHAR: return "long varchar"; case Types.NUMERIC: return "numeric" + precisionAndScale(precision, scale); case Types.REAL: return "real"; case Types.SMALLINT: return "smallint"; case Types.TIME: return "time"; case Types.TIMESTAMP: return "timestamp"; case Types.TINYINT: return "smallint"; case Types.VARBINARY: return "varchar " + precisionToLength(precision) + " for bit data"; case Types.VARCHAR: return "varchar" + precisionToLength(precision); default: throw new SQLException("Unknown external data type. JDBC type = " + jdbcType + ", external type name = " + rsmd.getColumnTypeName(idx)); } } /** * <p> * Turns precision into a length designator. * </p> * */ private static String precisionToLength(int precision) { return "( " + precision + " )"; } /** * <p> * Build a precision and scale designator. * </p> * */ private static String precisionAndScale(int precision, int scale) { return "( " + precision + ", " + scale + " )"; } }