Enum SqlType

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<SqlType>

    public enum SqlType
    extends java.lang.Enum<SqlType>
    Extends the information in Types.

    The information in the following conversions tables (from the JDBC 4.1 specification) is held in members of this class.

    Table B-1: JDBC Types Mapped to Java Types

     JDBC Type     Java Type
     ============= =========================
     CHAR          String
     VARCHAR       String
     LONGVARCHAR   String
     NUMERIC       java.math.BigDecimal
     DECIMAL       java.math.BigDecimal
     BIT           boolean
     BOOLEAN       boolean
     TINYINT       byte
     SMALLINT      short
     INTEGER       int
     BIGINT        long
     REAL          float
     FLOAT         double
     DOUBLE        double
     BINARY        byte[]
     VARBINARY     byte[]
     LONGVARBINARY byte[]
     DATE          java.sql.Date
     TIME          java.sql.Time
     TIMESTAMP     java.sql.Timestamp
     CLOB          java.sql.Clob
     BLOB          java.sql.Blob
     ARRAY         java.sql.Array
     DISTINCT      mapping of underlying type
     STRUCT        java.sql.Struct
     REF           java.sql.Ref
     DATALINK      java.net.URL
     JAVA_OBJECT   underlying Java class
     ROWID         java.sql.RowId
     NCHAR         String
     NVARCHAR      String
     LONGNVARCHAR  String
     NCLOB         java.sql.NClob
     SQLXML        java.sql.SQLXML
     

    Table B-2: Standard Mapping from Java Types to JDBC Types

     Java Type            JDBC Type
     ==================== ==============================================
     String               CHAR, VARCHAR, LONGVARCHAR, NCHAR, NVARCHAR or
                          LONGNVARCHAR
     java.math.BigDecimal NUMERIC
     boolean              BIT or BOOLEAN
     byte                 TINYINT
     short                SMALLINT
     int                  INTEGER
     long                 BIGINT
     float                REAL
     double               DOUBLE
     byte[]               BINARY, VARBINARY, or LONGVARBINARY
     java.sql.Date        DATE
     java.sql.Time        TIME
     java.sql.Timestamp   TIMESTAMP
     java.sql.Clob        CLOB
     java.sql.Blob        BLOB
     java.sql.Array       ARRAY
     java.sql.Struct      STRUCT
     java.sql.Ref         REF
     java.net.URL         DATALINK
     Java class           JAVA_OBJECT
     java.sql.RowId       ROWID
     java.sql.NClob       NCLOB
     java.sql.SQLXML      SQLXML
     

    TABLE B-3: Mapping from JDBC Types to Java Object Types

     JDBC Type     Java Object Type
     ============= ======================
     CHAR          String
     VARCHAR       String
     LONGVARCHAR   String
     NUMERIC       java.math.BigDecimal
     DECIMAL       java.math.BigDecimal
     BIT           Boolean
     BOOLEAN       Boolean
     TINYINT       Integer
     SMALLINT      Integer
     INTEGER       Integer
     BIGINT        Long
     REAL          Float
     FLOAT         Double
     DOUBLE        Double
     BINARY        byte[]
     VARBINARY     byte[]
     LONGVARBINARY byte[]
     DATE          java.sql.Date
     TIME          java.sql.Time
     TIMESTAMP     java.sql.Timestamp
     DISTINCT      Object type of underlying type
     CLOB          java.sql.Clob
     BLOB          java.sql.Blob
     ARRAY         java.sql.Array
     STRUCT        java.sql.Struct or java.sql.SQLData
     REF           java.sql.Ref
     DATALINK      java.net.URL
     JAVA_OBJECT   underlying Java class
     ROWID         java.sql.RowId
     NCHAR         String
     NVARCHAR      String
     LONGNVARCHAR  String
     NCLOB         java.sql.NClob
     SQLXML        java.sql.SQLXML
     

    TABLE B-4: Mapping from Java Object Types to JDBC Types

     Java Object Type     JDBC Type
     ==================== ===========================================
     String               CHAR, VARCHAR, LONGVARCHAR, NCHAR, NVARCHAR
                          or LONGNVARCHAR
     java.math.BigDecimal NUMERIC
     Boolean              BIT or BOOLEAN
     Byte                 TINYINT
     Short                SMALLINT
     Integer              INTEGER
     Long                 BIGINT
     Float                REAL
     Double               DOUBLE
     byte[]               BINARY, VARBINARY, or LONGVARBINARY
     java.math.BigInteger BIGINT
     java.sql.Date        DATE
     java.sql.Time        TIME
     java.sql.Timestamp   TIMESTAMP
     java.sql.Clob        CLOB
     java.sql.Blob        BLOB
     java.sql.Array       ARRAY
     java.sql.Struct      STRUCT
     java.sql.Ref         REF
     java.net.URL         DATALINK
     Java class           JAVA_OBJECT
     java.sql.RowId       ROWID
     java.sql.NClob       NCLOB
     java.sql.SQLXML      SQLXML
     java.util.Calendar   TIMESTAMP
     java.util.Date       TIMESTAMP
     

    TABLE B-5: Conversions performed by setObject and setNull between Java object types and target JDBC types

                          T S I B R F D D N B B C V L B V L D T T A B C S R D J R N N L N S
                          I M N I E L O E U I O H A O I A O A I I R L L T E A A O C V O C Q
                          N A T G A O U C M T O A R N N R N T M M R O O R F T V W H A N L L
                          Y L E I L A B I E   L R C G A B G E E E A B B U   A A I A R G O X
                          I L G N   T L M R   E   H V R I V E   S Y     C   L _ D R C N B M
                          N I E T     E A I   A   A A Y N A     T       T   I O     H V   L
                          T N R         L C   N   R R   A R     A           N B     A A
                            T                       C   R B     M           K J     R R
                                                    H   Y I     P                     C
     Java type
     ==================== = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     String               x x x x x x x x x x x x x x x x x x x x . . . . . . . . x x x . .
     java.math.BigDecimal x x x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     Boolean              x x x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     Byte                 x x x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     Short                x x x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     Integer              x x x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     Long                 x x x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     Float                x x x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     Double               x x x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     byte[]               . . . . . . . . . . . . . . x x x . . . . . . . . . . . . . . . .
     java.math.BigInteger . . . x . . . . . . . x x x . . . . . . . . . . . . . . . . . . .
     java.sql.Date        . . . . . . . . . . . x x x . . . x . x . . . . . . . . . . . . .
     java.sql.Time        . . . . . . . . . . . x x x . . . . x x . . . . . . . . . . . . .
     java.sql.Timestamp   . . . . . . . . . . . x x x . . . x x x . . . . . . . . . . . . .
     java.sql.Array       . . . . . . . . . . . . . . . . . . . . x . . . . . . . . . . . .
     java.sql.Blob        . . . . . . . . . . . . . . . . . . . . . x . . . . . . . . . . .
     java.sql.Clob        . . . . . . . . . . . . . . . . . . . . . . x . . . . . . . . . .
     java.sql.Struct      . . . . . . . . . . . . . . . . . . . . . . . x . . . . . . . . .
     java.sql.Ref         . . . . . . . . . . . . . . . . . . . . . . . . x . . . . . . . .
     java.net.URL         . . . . . . . . . . . . . . . . . . . . . . . . . x . . . . . . .
     Java class           . . . . . . . . . . . . . . . . . . . . . . . . . . x . . . . . .
     java.sql.Rowid       . . . . . . . . . . . . . . . . . . . . . . . . . . . x . . . . .
     java.sql.NClob       . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x .
     java.sql.SQLXML      . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x
     java.util.Calendar   . . . . . . . . . . . x x x . . . x x x . . . . . . . . . . . . .
     java.util.Date       . . . . . . . . . . . x x x . . . x x x . . . . . . . . . . . . .
     

    TABLE B-6: Use of ResultSet getter methods to retrieve JDBC data types

                          T S I B R F D D N B B C V L B V L D T T C B A R D S J R N N L N S
                          I M N I E L O E U I O H A O I A O A I I L L R E A T A O C V O C Q
                          N A T G A O U C M T O A R N N R N T M M O O R F T R V W H A N L L
                          Y L E I L A B I E   L R C G A B G E E E B B A   A U A I A R G O X
                          I L G N   T L M R   E   H V R I V E   S     Y   L C _ D R C N B M
                          N I E T     E A I   A   A A Y N A     T         I T O     H V   L
                          T N R         L C   N   R R   A R     A         N   B     A A
                            T                       C   R B     M         K   J     R R
                                                    H   Y I     P                     C
     Java type
     ==================== = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     getByte              X x x x x x x x x x x x x . . . . . . . . . . . . . . x . . . . .
     getShort             x X x x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     getInt               x x X x x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     getLong              x x x X x x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     getFloat             x x x x X x x x x x x x x . . . . . . . . . . . . . . . . . . . .
     getDouble            x x x x x X X x x x x x x . . . . . . . . . . . . . . . . . . . .
     getBigDecimal        x x x x x x x X X x x x x . . . . . . . . . . . . . . . . . . . .
     getBoolean           x x x x x x x x x X x x x . . . . . . . . . . . . . . . . . . . .
     getString            x x x x x x x x x x x X X x x x x x x x . . . . x . . . x x x . .
     getNString           x x x x x x x x x x x x x x x x x x x x . . . . x . . . X X x . .
     getBytes             . . . . . . . . . . . . . . X X x . . . . . . . . . . . . . . . .
     getDate              . . . . . . . . . . . x x x . . . X . x . . . . . . . . . . . . .
     getTime              . . . . . . . . . . . x x x . . . . X x . . . . . . . . . . . . .
     getTimestamp         . . . . . . . . . . . x x x . . . x x X . . . . . . . . . . . x .
     getAsciiStream       . . . . . . . . . . . x x X x x x . . . x . . . . . . . . . . . x
     getBinaryStream      . . . . . . . . . . . . . . x x X . . . . x . . . . . . . . . x x
     getCharacterStream   . . . . . . . . . . . x x X x x x . . . x . . . . . . . x x x x x
     getNCharacterStream  . . . . . . . . . . . x x x x x x . . . x . . . . . . . x x X x x
     getClob              . . . . . . . . . . . . . . . . . . . . X . . . . . . . . . . x .
     getNClob             . . . . . . . . . . . . . . . . . . . . x . . . . . . . . . . X .
     getBlob              . . . . . . . . . . . . . . . . . . . . . X . . . . . . . . . . .
     getArray             . . . . . . . . . . . . . . . . . . . . . . X . . . . . . . . . .
     getRef               . . . . . . . . . . . . . . . . . . . . . . . X . . . . . . . . .
     getURL               . . . . . . . . . . . . . . . . . . . . . . . . X . . . . . . . .
     getObject            x x x x x x x x x x x x x x x x x x x x x x x x x X X x x x x x x
     getRowId             . . . . . . . . . . . . . . . . . . . . . . . . . . . X . . . . .
     getSQLXML            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . X
     
    • Enum Constant Detail

      • BIT

        public static final SqlType BIT
      • BOOLEAN

        public static final SqlType BOOLEAN
      • TINYINT

        public static final SqlType TINYINT
      • SMALLINT

        public static final SqlType SMALLINT
      • INTEGER

        public static final SqlType INTEGER
      • BIGINT

        public static final SqlType BIGINT
      • NUMERIC

        public static final SqlType NUMERIC
      • DECIMAL

        public static final SqlType DECIMAL
      • FLOAT

        public static final SqlType FLOAT
      • REAL

        public static final SqlType REAL
      • DOUBLE

        public static final SqlType DOUBLE
      • DATE

        public static final SqlType DATE
      • TIME

        public static final SqlType TIME
      • TIMESTAMP

        public static final SqlType TIMESTAMP
      • INTERVAL_YEAR_MONTH

        public static final SqlType INTERVAL_YEAR_MONTH
      • INTERVAL_DAY_TIME

        public static final SqlType INTERVAL_DAY_TIME
      • CHAR

        public static final SqlType CHAR
      • VARCHAR

        public static final SqlType VARCHAR
      • LONGVARCHAR

        public static final SqlType LONGVARCHAR
      • BINARY

        public static final SqlType BINARY
      • VARBINARY

        public static final SqlType VARBINARY
      • LONGVARBINARY

        public static final SqlType LONGVARBINARY
      • NULL

        public static final SqlType NULL
      • ANY

        public static final SqlType ANY
      • SYMBOL

        public static final SqlType SYMBOL
      • MULTISET

        public static final SqlType MULTISET
      • ARRAY

        public static final SqlType ARRAY
      • BLOB

        public static final SqlType BLOB
      • CLOB

        public static final SqlType CLOB
      • SQLXML

        public static final SqlType SQLXML
      • MAP

        public static final SqlType MAP
      • DISTINCT

        public static final SqlType DISTINCT
      • STRUCT

        public static final SqlType STRUCT
      • REF

        public static final SqlType REF
      • DATALINK

        public static final SqlType DATALINK
      • JAVA_OBJECT

        public static final SqlType JAVA_OBJECT
      • ROWID

        public static final SqlType ROWID
      • NCHAR

        public static final SqlType NCHAR
      • NVARCHAR

        public static final SqlType NVARCHAR
      • LONGNVARCHAR

        public static final SqlType LONGNVARCHAR
      • NCLOB

        public static final SqlType NCLOB
      • ROW

        public static final SqlType ROW
      • OTHER

        public static final SqlType OTHER
      • CURSOR

        public static final SqlType CURSOR
      • TIME_WITH_TIMEZONE

        public static final SqlType TIME_WITH_TIMEZONE
      • TIMESTAMP_WITH_TIMEZONE

        public static final SqlType TIMESTAMP_WITH_TIMEZONE
      • COLUMN_LIST

        public static final SqlType COLUMN_LIST
    • Field Detail

      • id

        public final int id
        Type id as appears in Types, e.g. Types.INTEGER.
      • clazz

        public final java.lang.Class clazz
        Default Java type for this SQL type, as described in table B-1.
      • internal

        public final java.lang.Class internal
        Class used internally in Calcite to represent instances of this type.
      • serial

        public final java.lang.Class serial
        Class used to serialize values of this type as JSON.
      • BY_ID

        private static final java.util.Map<java.lang.Integer,​SqlType> BY_ID
      • SET_LIST

        public static final java.util.Map<java.lang.Class,​java.util.EnumSet<SqlType>> SET_LIST
    • Constructor Detail

      • SqlType

        private SqlType​(int id,
                        java.lang.Class clazz,
                        java.lang.Class internal,
                        java.lang.Class serial)
      • SqlType

        private SqlType​(int id,
                        java.lang.Class clazz,
                        java.lang.Class internal)
      • SqlType

        private SqlType​(int id,
                        java.lang.Class clazz)
    • Method Detail

      • values

        public static SqlType[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (SqlType c : SqlType.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static SqlType valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • valueOf

        public static SqlType valueOf​(int type)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        type - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • boxedClass

        public java.lang.Class boxedClass()
        Returns the boxed type.
      • getSetConversions

        public static java.lang.Iterable<java.util.Map.Entry<java.lang.Class,​SqlType>> getSetConversions()
        Returns the entries in JDBC table B-5.
      • concat

        @SafeVarargs
        private static <E extends java.lang.Enum<E>> java.util.EnumSet<E> concat​(java.util.Collection<E>... ess)
      • canSet

        public static boolean canSet​(java.lang.Class aClass,
                                     SqlType sqlType)
        Returns whether PreparedStatement.setObject(int, java.lang.Object, int) and PreparedStatement.setNull(int, int) can assign a value of a particular class to a column of a particular SQL type.

        The JDBC standard describes the mapping in table B-5.

      • canGet

        public static boolean canGet​(SqlType.Method method,
                                     SqlType sqlType)
        Returns whether ResultSet.getInt(int) and similar methods can convert a value to a particular SQL type.

        The JDBC standard describes the mapping in table B-6.