Java Code Examples for java.sql.Types#NCHAR

The following examples show how to use java.sql.Types#NCHAR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableJDBC.java    From Rel with Apache License 2.0 6 votes vote down vote up
@Override
public void delete(Generator generator, ValueTuple tuple) {
	PreparedStatement preparedStatement;
	String[] values = CSVLineParse.parseTrimmed(tuple.toCSV());
	StringBuffer line = new StringBuffer("delete from " + meta.getTable() + " where ");
	try {
		ResultSet resultSet = statement.executeQuery("select * from " + meta.getTable());
		for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
			int type = resultSet.getMetaData().getColumnType(i);
			line.append(resultSet.getMetaData().getColumnName(i) + "=");
			if (type == Types.CHAR || type == Types.VARCHAR || type == Types.LONGVARCHAR || type == Types.NCHAR || type == Types.NVARCHAR)
				line.append("\'" + values[i - 1] + "\' AND ");
			else
				line.append(values[i - 1] + " AND ");
		}
		preparedStatement = connect.prepareStatement(line.substring(0, line.length() - 5) + ";");
		preparedStatement.executeUpdate();

	} catch (SQLException e) {
		System.out.println("TableJDBC[3]: error " + e);
	}
}
 
Example 2
Source File: DB297Dialect.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
	// See HHH-12753
	// It seems that DB2's JDBC 4.0 support as of 9.5 does not support the N-variant methods like
	// NClob or NString.  Therefore here we overwrite the sql type descriptors to use the non-N variants
	// which are supported.
	switch ( sqlCode ) {
		case Types.NCHAR:
			return CharTypeDescriptor.INSTANCE;

		case Types.NCLOB:
			if ( useInputStreamToInsertBlob() ) {
				return ClobTypeDescriptor.STREAM_BINDING;
			}
			else {
				return ClobTypeDescriptor.CLOB_BINDING;
			}

		case Types.NVARCHAR:
			return VarcharTypeDescriptor.INSTANCE;

		default:
			return super.getSqlTypeDescriptorOverride( sqlCode );
	}
}
 
Example 3
Source File: JdbcThinUtils.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param type a value from <code>java.sql.Types</code>.
 * @return {@code true} if type is plain and supported by thin JDBC driver.
 */
public static boolean isPlainJdbcType(int type) {
    return type != Types.ARRAY
        && type != Types.BLOB
        && type != Types.CLOB
        && type != Types.DATALINK
        && type != Types.JAVA_OBJECT
        && type != Types.NCHAR
        && type != Types.NVARCHAR
        && type != Types.LONGNVARCHAR
        && type != Types.REF
        && type != Types.ROWID
        && type != Types.SQLXML;
}
 
Example 4
Source File: YuGongUtils.java    From yugong with GNU General Public License v2.0 5 votes vote down vote up
public static Object encoding(Object source, int sqlType, String sourceEncoding, String targetEncoding) {
    switch (sqlType) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CLOB:
        case Types.NCLOB:
            if (source instanceof String) {
                String str = (String) source;
                if (false == StringUtils.isEmpty(str)) {
                    if (false == StringUtils.equalsIgnoreCase(sourceEncoding, targetEncoding)) {
                        try {
                            byte[] bytes = null;
                            if (StringUtils.isBlank(sourceEncoding)) {
                                bytes = str.getBytes();
                            } else {
                                bytes = str.getBytes(sourceEncoding);
                            }

                            if (StringUtils.isBlank(targetEncoding)) {
                                return new String(bytes);
                            } else {
                                return new String(bytes, targetEncoding);
                            }
                        } catch (UnsupportedEncodingException e) {
                            throw new IllegalArgumentException(e.getMessage(), e);
                        }
                    }
                }
            }
    }

    return source;
}
 
Example 5
Source File: DBTablePrinter.java    From salesforce-jdbc with MIT License 5 votes vote down vote up
/**
 * Takes a generic SQL type and returns the category this type
 * belongs to. Types are categorized according to print formatting
 * needs:
 * <p>
 * Integers should not be truncated so column widths should
 * be adjusted without a column width limit. Text columns should be
 * left justified and can be truncated to a max. column width etc...</p>
 * <p>
 * See also: <a target="_blank"
 * href="http://docs.oracle.com/javase/8/docs/api/java/sql/Types.html">
 * java.sql.Types</a>
 *
 * @param type Generic SQL type
 * @return The category this type belongs to
 */
private static int whichCategory(int type) {
    switch (type) {
        case Types.BIGINT:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return CATEGORY_INTEGER;

        case Types.REAL:
        case Types.DOUBLE:
        case Types.DECIMAL:
            return CATEGORY_DOUBLE;

        case Types.DATE:
        case Types.TIME:
        case Types.TIME_WITH_TIMEZONE:
        case Types.TIMESTAMP:
        case Types.TIMESTAMP_WITH_TIMEZONE:
            return CATEGORY_DATETIME;

        case Types.BOOLEAN:
            return CATEGORY_BOOLEAN;

        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CHAR:
        case Types.NCHAR:
            return CATEGORY_STRING;

        default:
            return CATEGORY_OTHER;
    }
}
 
Example 6
Source File: RowSetMetaDataTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
    return new Object[][]{
        {Types.CHAR, "java.lang.String"},
        {Types.NCHAR, "java.lang.String"},
        {Types.VARCHAR, "java.lang.String"},
        {Types.NVARCHAR, "java.lang.String"},
        {Types.LONGVARCHAR, "java.lang.String"},
        {Types.LONGNVARCHAR, "java.lang.String"},
        {Types.NUMERIC, "java.math.BigDecimal"},
        {Types.DECIMAL, "java.math.BigDecimal"},
        {Types.BIT, "java.lang.Boolean"},
        {Types.TINYINT, "java.lang.Byte"},
        {Types.SMALLINT, "java.lang.Short"},
        {Types.INTEGER, "java.lang.Integer"},
        {Types.FLOAT, "java.lang.Double"},
        {Types.DOUBLE, "java.lang.Double"},
        {Types.BINARY, "byte[]"},
        {Types.VARBINARY, "byte[]"},
        {Types.LONGVARBINARY, "byte[]"},
        {Types.DATE, "java.sql.Date"},
        {Types.TIME, "java.sql.Time"},
        {Types.TIMESTAMP, "java.sql.Timestamp"},
        {Types.CLOB, "java.sql.Clob"},
        {Types.BLOB, "java.sql.Blob"}

    };

}
 
Example 7
Source File: RowSetMetaDataTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
    return new Object[][]{
        {Types.CHAR, "java.lang.String"},
        {Types.NCHAR, "java.lang.String"},
        {Types.VARCHAR, "java.lang.String"},
        {Types.NVARCHAR, "java.lang.String"},
        {Types.LONGVARCHAR, "java.lang.String"},
        {Types.LONGNVARCHAR, "java.lang.String"},
        {Types.NUMERIC, "java.math.BigDecimal"},
        {Types.DECIMAL, "java.math.BigDecimal"},
        {Types.BIT, "java.lang.Boolean"},
        {Types.TINYINT, "java.lang.Byte"},
        {Types.SMALLINT, "java.lang.Short"},
        {Types.INTEGER, "java.lang.Integer"},
        {Types.FLOAT, "java.lang.Double"},
        {Types.DOUBLE, "java.lang.Double"},
        {Types.BINARY, "byte[]"},
        {Types.VARBINARY, "byte[]"},
        {Types.LONGVARBINARY, "byte[]"},
        {Types.DATE, "java.sql.Date"},
        {Types.TIME, "java.sql.Time"},
        {Types.TIMESTAMP, "java.sql.Timestamp"},
        {Types.CLOB, "java.sql.Clob"},
        {Types.BLOB, "java.sql.Blob"}

    };

}
 
Example 8
Source File: DBTablePrinter.java    From salesforce-jdbc with MIT License 5 votes vote down vote up
/**
 * Takes a generic SQL type and returns the category this type
 * belongs to. Types are categorized according to print formatting
 * needs:
 * <p>
 * Integers should not be truncated so column widths should
 * be adjusted without a column width limit. Text columns should be
 * left justified and can be truncated to a max. column width etc...</p>
 * <p>
 * See also: <a target="_blank"
 * href="http://docs.oracle.com/javase/8/docs/api/java/sql/Types.html">
 * java.sql.Types</a>
 *
 * @param type Generic SQL type
 * @return The category this type belongs to
 */
private static int whichCategory(int type) {
    switch (type) {
        case Types.BIGINT:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return CATEGORY_INTEGER;

        case Types.REAL:
        case Types.DOUBLE:
        case Types.DECIMAL:
            return CATEGORY_DOUBLE;

        case Types.DATE:
        case Types.TIME:
        case Types.TIME_WITH_TIMEZONE:
        case Types.TIMESTAMP:
        case Types.TIMESTAMP_WITH_TIMEZONE:
            return CATEGORY_DATETIME;

        case Types.BOOLEAN:
            return CATEGORY_BOOLEAN;

        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CHAR:
        case Types.NCHAR:
            return CATEGORY_STRING;

        default:
            return CATEGORY_OTHER;
    }
}
 
Example 9
Source File: DB2ColumnMetadataReaderTest.java    From virtual-schemas with MIT License 5 votes vote down vote up
@ValueSource(ints = { Types.VARCHAR, Types.NVARCHAR, Types.LONGNVARCHAR, Types.CHAR, Types.NCHAR,
        Types.LONGNVARCHAR })
@ParameterizedTest
void testMapJdbcVarcharSizeLesserThanExasolMaxVarcharSize(final int type) {
    final JdbcTypeDescription jdbcTypeDescription = new JdbcTypeDescription(type, 0, 10, 0, "");
    assertThat(this.db2ColumnMetadataReader.mapJdbcType(jdbcTypeDescription),
            equalTo(DataType.createVarChar(10, DataType.ExaCharset.UTF8)));
}
 
Example 10
Source File: ResultSetTableModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected static Class<? extends Object> getTypeClass(DBColumn col) {
    int colType = col.getJdbcType();

    if (colType == Types.BIT && col.getPrecision() <= 1) {
        colType = Types.BOOLEAN;
    }

    switch (colType) {
        case Types.BOOLEAN:
            return Boolean.class;
        case Types.TIME:
            return Time.class;
        case Types.DATE:
            return Date.class;
        case Types.TIMESTAMP:
        case DBReadWriteHelper.SQL_TYPE_ORACLE_TIMESTAMP:
        case DBReadWriteHelper.SQL_TYPE_ORACLE_TIMESTAMP_WITH_TZ:
            return Timestamp.class;
        case Types.BIGINT:
            return BigInteger.class;
        case Types.DOUBLE:
            return Double.class;
        case Types.FLOAT:
        case Types.REAL:
            return Float.class;
        case Types.DECIMAL:
        case Types.NUMERIC:
            return BigDecimal.class;
        case Types.INTEGER:
        case Types.SMALLINT:
        case Types.TINYINT:
            return Long.class;

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.ROWID:
            return String.class;

        case Types.BIT:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
            return Blob.class;
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CLOB:
        case Types.NCLOB: /*NCLOB */
            return Clob.class;
        case Types.OTHER:
        default:
            return Object.class;
    }
}
 
Example 11
Source File: SqoopHCatUtilities.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 4 votes vote down vote up
/**
 * Resolve a database-specific type to HCat data type. Largely follows Sqoop's
 * hive translation.
 * @param sqlType
 *          sql type
 * @return hcat type
 */
public static String toHCatType(int sqlType) {
  switch (sqlType) {

  // Ideally TINYINT and SMALLINT should be mapped to their
  // HCat equivalents tinyint and smallint respectively
  // But the Sqoop Java type conversion has them mapped to Integer
  // Even though the referenced Java doc clearly recommends otherwise.
  // Changing this now can cause many of the sequence file usages to
  // break as value class implementations will change. So, we
  // just use the same behavior here.
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.INTEGER:
      return "int";

    case Types.VARCHAR:
      return "varchar";
    case Types.CHAR:
      return "char";
    case Types.LONGVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.CLOB:
      return "string";

    case Types.FLOAT:
    case Types.REAL:
      return "float";

    case Types.NUMERIC:
    case Types.DECIMAL:
      return "decimal";

    case Types.DOUBLE:
      return "double";

    case Types.BIT:
    case Types.BOOLEAN:
      return "boolean";

    case Types.BIGINT:
      return "bigint";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
    case Types.LONGVARBINARY:
      return "binary";

    default:
      throw new IllegalArgumentException(
        "Cannot convert SQL type to HCatalog type " + sqlType);
  }
}
 
Example 12
Source File: ResultSetRecordSet.java    From nifi with Apache License 2.0 4 votes vote down vote up
private static RecordFieldType getFieldType(final int sqlType, final String valueClassName) {
    switch (sqlType) {
        case Types.BIGINT:
        case Types.ROWID:
            return RecordFieldType.LONG;
        case Types.BIT:
        case Types.BOOLEAN:
            return RecordFieldType.BOOLEAN;
        case Types.CHAR:
            return RecordFieldType.CHAR;
        case Types.DATE:
            return RecordFieldType.DATE;
        case Types.NUMERIC:
        case Types.DECIMAL:
            return RecordFieldType.DECIMAL;
        case Types.DOUBLE:
        case Types.REAL:
            return RecordFieldType.DOUBLE;
        case Types.FLOAT:
            return RecordFieldType.FLOAT;
        case Types.INTEGER:
            return RecordFieldType.INT;
        case Types.SMALLINT:
            return RecordFieldType.SHORT;
        case Types.TINYINT:
            return RecordFieldType.BYTE;
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NULL:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            return RecordFieldType.STRING;
        case Types.OTHER:
        case Types.JAVA_OBJECT:
            if (STRING_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.STRING;
            }
            if (INT_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.INT;
            }
            if (LONG_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.LONG;
            }
            if (DATE_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DATE;
            }
            if (FLOAT_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.FLOAT;
            }
            if (DOUBLE_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DOUBLE;
            }
            if (BIGDECIMAL_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DECIMAL;
            }

            return RecordFieldType.RECORD;
        case Types.TIME:
        case Types.TIME_WITH_TIMEZONE:
            return RecordFieldType.TIME;
        case Types.TIMESTAMP:
        case Types.TIMESTAMP_WITH_TIMEZONE:
        case -101: // Oracle's TIMESTAMP WITH TIME ZONE
        case -102: // Oracle's TIMESTAMP WITH LOCAL TIME ZONE
            return RecordFieldType.TIMESTAMP;
    }

    return RecordFieldType.STRING;
}
 
Example 13
Source File: SQLTypeUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Convert sql types to String for display
 *
 * @param sqlType the type number from java.sql.Types
 * @return the type name
 */
static public String getSqlTypeString(int sqlType) {
    switch (sqlType) {
        case Types.BIGINT:
            return "BIGINT"; //NOI18N
        case Types.BINARY:
            return "BINARY"; //NOI18N
        case Types.BIT:
            return "BIT"; //NOI18N
        case Types.NCHAR:
            return "NCHAR"; //NOI18N
        case Types.CHAR:
            return "CHAR"; //NOI18N
        case Types.DATE:
            return "DATE"; //NOI18N
        case Types.DECIMAL:
            return "DECIMAL"; //NOI18N
        case Types.DOUBLE:
            return "DOUBLE"; //NOI18N
        case Types.FLOAT:
            return "FLOAT"; //NOI18N
        case Types.INTEGER:
            return "INTEGER"; //NOI18N
        case Types.LONGVARBINARY:
            return "LONGVARBINARY"; //NOI18N
        case Types.LONGNVARCHAR:
            return "LONGNVARCHAR"; //NOI18N
        case Types.LONGVARCHAR:
            return "LONGVARCHAR"; //NOI18N
        case Types.NULL:
            return "NULL"; //NOI18N
        case Types.NUMERIC:
            return "NUMERIC"; //NOI18N
        case Types.OTHER:
            return "OTHER"; //NOI18N
        case Types.REAL:
            return "REAL"; //NOI18N
        case Types.SMALLINT:
            return "SMALLINT"; //NOI18N
        case Types.TIME:
            return "TIME"; //NOI18N
        case Types.TIMESTAMP:
            return "TIMESTAMP"; //NOI18N
        case Types.TINYINT:
            return "TINYINT"; //NOI18N
        case Types.VARBINARY:
            return "VARBINARY"; //NOI18N
        case Types.NVARCHAR:
            return "NVARCHAR";
        case Types.VARCHAR:
            return "VARCHAR"; //NOI18N
        case Types.JAVA_OBJECT:
            return "JAVA_OBJECT"; //NOI18N
        case Types.DISTINCT:
            return "DISTINCT"; //NOI18N
        case Types.STRUCT:
            return "STRUCT"; //NOI18N
        case Types.ARRAY:
            return "ARRAY"; //NOI18N
        case Types.BLOB:
            return "BLOB"; //NOI18N
        case Types.NCLOB:
            return "NCLOB";
        case Types.CLOB:
            return "CLOB"; //NOI18N
        case Types.REF:
            return "REF"; //NOI18N
        default:
            Logger.getLogger(SQLTypeUtil.class.getName()).log(Level.WARNING, "Unknown JDBC column type: {0}. Returns null.", sqlType);
            return "UNKNOWN"; //NOI18N
    }
}
 
Example 14
Source File: Converters.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Get JDBC {@link Types} type for given {@link GFXDType}.
 */
public static int getJdbcType(GFXDType type) {
  switch (type) {
    case ARRAY:
      return Types.ARRAY;
    case BIGINT:
      return Types.BIGINT;
    case BINARY:
      return Types.BINARY;
    case BLOB:
      return Types.BLOB;
    case BOOLEAN:
      return Types.BOOLEAN;
    case CHAR:
      return Types.CHAR;
    case CLOB:
      return Types.CLOB;
    case DATALINK:
      return Types.DATALINK;
    case DATE:
      return Types.DATE;
    case DECIMAL:
      return Types.DECIMAL;
    case DISTINCT:
      return Types.DISTINCT;
    case DOUBLE:
      return Types.DOUBLE;
    case FLOAT:
      return Types.FLOAT;
    case INTEGER:
      return Types.INTEGER;
    case JAVA_OBJECT:
      return Types.JAVA_OBJECT;
    case JSON_OBJECT:
      return TYPE_JSON_OBJECT;
    case LONGNVARCHAR:
      return Types.LONGNVARCHAR;
    case LONGVARBINARY:
      return Types.LONGVARBINARY;
    case LONGVARCHAR:
      return Types.LONGVARCHAR;
    case NCHAR:
      return Types.NCHAR;
    case NCLOB:
      return Types.NCLOB;
    case NULLTYPE:
      return Types.NULL;
    case NVARCHAR:
      return Types.NVARCHAR;
    case OTHER:
      return Types.OTHER;
    case PDX_OBJECT:
      return TYPE_PDX_OBJECT;
    case REAL:
      return Types.REAL;
    case REF:
      return Types.REF;
    case ROWID:
      return Types.ROWID;
    case SMALLINT:
      return Types.SMALLINT;
    case SQLXML:
      return Types.SQLXML;
    case STRUCT:
      return Types.STRUCT;
    case TIME:
      return Types.TIME;
    case TIMESTAMP:
      return Types.TIMESTAMP;
    case TINYINT:
      return Types.TINYINT;
    case VARBINARY:
      return Types.VARBINARY;
    case VARCHAR:
      return Types.VARCHAR;
    default:
      return Types.OTHER;
  }
}
 
Example 15
Source File: JDBCConnection.java    From dbtransfer with GNU Lesser General Public License v2.1 4 votes vote down vote up
public List<ColumnDefinition> getColumnList( Name table ) throws Exception
    {
        List<ColumnDefinition> list = MAP_TABLE_COLUMNS.get( table.originalName );
        if( list == null )
        {
            testInitConnection();
            DatabaseMetaData rsmd = connection.getMetaData();
            ResultSet rs = rsmd.getColumns( catalog, dbSchema, table.originalName, null );
            list = new LinkedList<ColumnDefinition>();
            Map<String,ColumnDefinition> cols = new HashMap<String, ColumnDefinition>();
            if( debug )
            {
            	System.out.println( "COL FOR TABLE: <" + table.originalName + ">" );
            }
            while( rs.next() )
            {
            	String n;
            	if( table.originalName.equals( table.originalName.toUpperCase() ) )
            	{
            		n = rs.getString( 4 );
            	}
            	else
            	{
            		n = "\"" + rs.getString( 4 ) + "\"";
            	}
            	Name name = new Name( n );
            	if( debug )
                {
                	System.out.println( "COL: <" + name.originalName + ">" );
                }
//                    System.out.println( "COL: " + name.originalName );
                if( !cols.containsKey( name.saneName ) )
                {
                    ColumnDefinition col = new ColumnDefinition();
                    col.name = name;
                    col.sqlTypeName = rs.getString( 6 );
                    col.sqlType = rs.getInt( 5 );
                    if( rs.getInt( 5 ) == Types.CHAR
                                    || rs.getInt( 5 ) == Types.LONGVARCHAR
                                    || rs.getInt( 5 ) == Types.VARCHAR
                                    || rs.getInt( 5 ) == Types.NCHAR
                                    || rs.getInt( 5 ) == Types.LONGNVARCHAR
                                    || rs.getInt( 5 ) == Types.NVARCHAR )
                    {
                            col.sqlSize = rs.getInt( 7 );
                    }
                    col.defaultValue = helper.normalizeDefault( rs.getString( 13 ) );
                    col.isNotNull = "NO".equals( rs.getString( 18 ).trim() );
                    cols.put( col.name.saneName, col );
                    list.add( col );
//                        System.out.println( "Adding col: " + table.originalName + " - " + name );
                }
                else
                {
                    System.out.println( "Ignoring duplicate: " + table.originalName + " - " + name );
                    new Exception( "Ignoring duplicate: " + table.originalName + " - " + name ).printStackTrace();;
                }
            }
            rs.close();
            list = Collections.unmodifiableList( list );
            MAP_TABLE_COLUMNS.put( table.originalName, list );
        }
//            System.out.println( "COLSS size: " + list.size() );
        return list;
    }
 
Example 16
Source File: MTypesTranslator.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public TClass typeClassForJDBCType(int jdbcType,
                                   String schemaName, String tableName, String columnName) {
    switch (jdbcType) {
    case Types.BIGINT:
        return MNumeric.BIGINT;
    case Types.BINARY:
    case Types.BIT:
        return MBinary.BINARY;
    case Types.CHAR:
    case Types.NCHAR:
        return MString.CHAR;
    case Types.CLOB:
    case Types.NCLOB:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
  //case Types.SQLXML:
        return MString.LONGTEXT;
    case Types.DATE:
        return MDateAndTime.DATE;
    case Types.DECIMAL:
    case Types.NUMERIC:
        return MNumeric.DECIMAL;
    case Types.DOUBLE:
        return MApproximateNumber.DOUBLE;
    case Types.FLOAT:
    case Types.REAL:
        return MApproximateNumber.FLOAT;
    case Types.INTEGER:
        return MNumeric.INT;
    case Types.SMALLINT:
        return MNumeric.SMALLINT;
    case Types.TIME:
        return MDateAndTime.TIME;
    case Types.TIMESTAMP:
        return MDateAndTime.DATETIME; // (Not TIMESTAMP.)
    case Types.TINYINT:
        return MNumeric.TINYINT;
    case Types.VARBINARY:
        return MBinary.VARBINARY;
    case Types.VARCHAR:
    case Types.NVARCHAR:
        return MString.VARCHAR;
    default:
        return super.typeClassForJDBCType(jdbcType, schemaName, tableName, columnName);
    }
}
 
Example 17
Source File: DatabaseStatement.java    From sndml3 with MIT License 4 votes vote down vote up
private static String sqlTypeName(int sqltype) {
	switch (sqltype) {
		case Types.ARRAY:         return "ARRAY";
		case Types.BIGINT:        return "BIGINT";
		case Types.BINARY:        return "BINARY";
		case Types.BIT:           return "BIT";
		case Types.BLOB:          return "BLOB";
		case Types.BOOLEAN:       return "BOOLEAN";
		case Types.CHAR:          return "CHAR";
		case Types.CLOB:          return "CLOB";
		case Types.DATALINK:      return "DATALINK";
		case Types.DATE:          return "DATE";
		case Types.DECIMAL:       return "DECIMAL";
		case Types.DISTINCT:      return "DISTINCT";
		case Types.DOUBLE:        return "DOUBLE";
		case Types.FLOAT:         return "FLOAT";
		case Types.INTEGER:       return "INTEGER";
		case Types.JAVA_OBJECT:   return "JAVA_OBJECT";
		case Types.LONGNVARCHAR:  return "LONGNVARCHAR";
		case Types.LONGVARBINARY: return "LONGVARBINARY";
		case Types.LONGVARCHAR:   return "LONGVARCHAR";
		case Types.NCHAR:         return "NCHAR";
		case Types.NCLOB:         return "NCLOB";
		case Types.NULL:          return "NULL";
		case Types.NUMERIC:       return "NUMERIC";
		case Types.NVARCHAR:      return "NVARCHAR";
		case Types.OTHER:         return "OTHER";
		case Types.REAL:          return "REAL";
		case Types.REF:           return "REF";
		case Types.ROWID:         return "ROWID";
		case Types.SMALLINT:      return "SMALLINT";
		case Types.SQLXML:        return "SQLXML";
		case Types.STRUCT:        return "STRUCT";
		case Types.TIME:          return "TIME";
		case Types.TIMESTAMP:     return "TIMESTAMP";
		case Types.TINYINT:       return "TINYINT";
		case Types.VARBINARY:     return "VARBINARY";
		case Types.VARCHAR:       return "VARCHAR";
		default: return Integer.toString(sqltype);
	}
}
 
Example 18
Source File: DataDrivenDBInputFormat.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 4 votes vote down vote up
/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits.
 */
protected DBSplitter getSplitter(int sqlDataType, long splitLimit) {
  switch (sqlDataType) {
  case Types.NUMERIC:
  case Types.DECIMAL:
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new BigDecimalSplitter();

  case Types.BIT:
  case Types.BOOLEAN:
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new BooleanSplitter();

  case Types.INTEGER:
  case Types.TINYINT:
  case Types.SMALLINT:
  case Types.BIGINT:
    return new IntegerSplitter();

  case Types.REAL:
  case Types.FLOAT:
  case Types.DOUBLE:
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new FloatSplitter();

  case Types.NVARCHAR:
  case Types.NCHAR:
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new NTextSplitter();

  case Types.CHAR:
  case Types.VARCHAR:
  case Types.LONGVARCHAR:
    if(splitLimit >= 0) {
       throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new TextSplitter();

  case Types.DATE:
  case Types.TIME:
  case Types.TIMESTAMP:
    return new DateSplitter();

  default:
    // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB,
    // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT.
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return null;
  }
}
 
Example 19
Source File: ResultConvertUtils.java    From dts with Apache License 2.0 4 votes vote down vote up
private static Object getDataByType(int index, int columnType, ResultSet resultSet) throws SQLException {
    if (columnType == Types.BIT) {
        return resultSet.getByte(index);
    }
    if (columnType == Types.TINYINT) {
        return resultSet.getByte(index);
    }
    if (columnType == Types.SMALLINT) {
        return resultSet.getShort(index);
    }
    if (columnType == Types.INTEGER) {
        return resultSet.getInt(index);
    }
    if (columnType == Types.BIGINT) {
        return resultSet.getLong(index);
    }
    if (columnType == Types.FLOAT) {
        return resultSet.getFloat(index);
    }
    if (columnType == Types.DOUBLE) {
        return resultSet.getDouble(index);
    }
    if (columnType == Types.NUMERIC) {
        return resultSet.getInt(index);
    }
    if (columnType == Types.DECIMAL) {
        return resultSet.getBigDecimal(index);
    }
    if (columnType == Types.CHAR) {
        return resultSet.getString(index);
    }
    if (columnType == Types.VARCHAR) {
        return resultSet.getString(index);
    }
    if (columnType == Types.LONGNVARCHAR) {
        return resultSet.getString(index);
    }
    if (columnType == Types.DATE) {
        return resultSet.getDate(index);
    }
    if (columnType == Types.TIME) {
        return resultSet.getTime(index);
    }
    if (columnType == Types.NCHAR) {
        return resultSet.getNString(index);
    }
    if (columnType == Types.NVARCHAR) {
        return resultSet.getNString(index);
    }
    if (columnType == Types.OTHER) {
        return resultSet.getObject(index);
    }
    if (columnType == Types.BLOB) {
        return resultSet.getBlob(index);
    }
    if (columnType == Types.BOOLEAN) {
        return resultSet.getBoolean(index);
    }
    if (columnType == Types.ARRAY) {
        return resultSet.getArray(index);
    }
    if (columnType == Types.TIMESTAMP) {
        return resultSet.getTimestamp(index);
    }
    return resultSet.getObject(index);
}
 
Example 20
Source File: MysqlDefs.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
public static int javaTypeMysql(int javaType) {

		switch (javaType) {
		case Types.NUMERIC:
			return MysqlDefs.FIELD_TYPE_DECIMAL;

		case Types.DECIMAL:
			return MysqlDefs.FIELD_TYPE_NEW_DECIMAL;

		case Types.TINYINT:
			return MysqlDefs.FIELD_TYPE_TINY;

		case Types.SMALLINT:
			return MysqlDefs.FIELD_TYPE_SHORT;

		case Types.INTEGER:
			return MysqlDefs.FIELD_TYPE_LONG;

		case Types.REAL:
			return MysqlDefs.FIELD_TYPE_FLOAT;

		case Types.DOUBLE:
			return MysqlDefs.FIELD_TYPE_DOUBLE;

		case Types.NULL:
			return MysqlDefs.FIELD_TYPE_NULL;

		case Types.TIMESTAMP:
			return MysqlDefs.FIELD_TYPE_TIMESTAMP;

		case Types.BIGINT:
			return MysqlDefs.FIELD_TYPE_LONGLONG;

		case Types.DATE:
			return MysqlDefs.FIELD_TYPE_DATE;

		case Types.TIME:
			return MysqlDefs.FIELD_TYPE_TIME;

		case Types.VARBINARY:
			return MysqlDefs.FIELD_TYPE_TINY_BLOB;

		case Types.LONGVARBINARY:
			return MysqlDefs.FIELD_TYPE_BLOB;
            //对应sqlserver的image类型
            case 27:
                return MysqlDefs.FIELD_TYPE_BLOB;

		case Types.VARCHAR:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;

		case Types.CHAR:
			return MysqlDefs.FIELD_TYPE_STRING;

		case Types.BINARY:
			return MysqlDefs.FIELD_TYPE_GEOMETRY;

		case Types.BIT:
			return MysqlDefs.FIELD_TYPE_BIT;
		case Types.CLOB:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;
		case Types.BLOB:
			return MysqlDefs.FIELD_TYPE_BLOB;

		//修改by     [email protected]
		// 当jdbc连接非mysql的数据库时,需要把对应类型映射为mysql的类型,否则应用端会出错
			case Types.NVARCHAR:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;
			case Types.NCHAR:
				return MysqlDefs.FIELD_TYPE_STRING;
			case Types.NCLOB:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;
			case Types.LONGNVARCHAR:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;

		default:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;   //其他未知类型返回字符类型
		//	return Types.VARCHAR;
		}

	}