1/* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25package java.sql; 26 27/** 28 * <P>Defines the constants that are used to identify generic 29 * SQL types, called JDBC types. 30 * 31 * @see SQLType 32 * @since 1.8 33 */ 34public enum JDBCType implements SQLType { 35 36 /** 37 * Identifies the generic SQL type {@code BIT}. 38 */ 39 BIT(Types.BIT), 40 /** 41 * Identifies the generic SQL type {@code TINYINT}. 42 */ 43 TINYINT(Types.TINYINT), 44 /** 45 * Identifies the generic SQL type {@code SMALLINT}. 46 */ 47 SMALLINT(Types.SMALLINT), 48 /** 49 * Identifies the generic SQL type {@code INTEGER}. 50 */ 51 INTEGER(Types.INTEGER), 52 /** 53 * Identifies the generic SQL type {@code BIGINT}. 54 */ 55 BIGINT(Types.BIGINT), 56 /** 57 * Identifies the generic SQL type {@code FLOAT}. 58 */ 59 FLOAT(Types.FLOAT), 60 /** 61 * Identifies the generic SQL type {@code REAL}. 62 */ 63 REAL(Types.REAL), 64 /** 65 * Identifies the generic SQL type {@code DOUBLE}. 66 */ 67 DOUBLE(Types.DOUBLE), 68 /** 69 * Identifies the generic SQL type {@code NUMERIC}. 70 */ 71 NUMERIC(Types.NUMERIC), 72 /** 73 * Identifies the generic SQL type {@code DECIMAL}. 74 */ 75 DECIMAL(Types.DECIMAL), 76 /** 77 * Identifies the generic SQL type {@code CHAR}. 78 */ 79 CHAR(Types.CHAR), 80 /** 81 * Identifies the generic SQL type {@code VARCHAR}. 82 */ 83 VARCHAR(Types.VARCHAR), 84 /** 85 * Identifies the generic SQL type {@code LONGVARCHAR}. 86 */ 87 LONGVARCHAR(Types.LONGVARCHAR), 88 /** 89 * Identifies the generic SQL type {@code DATE}. 90 */ 91 DATE(Types.DATE), 92 /** 93 * Identifies the generic SQL type {@code TIME}. 94 */ 95 TIME(Types.TIME), 96 /** 97 * Identifies the generic SQL type {@code TIMESTAMP}. 98 */ 99 TIMESTAMP(Types.TIMESTAMP), 100 /** 101 * Identifies the generic SQL type {@code BINARY}. 102 */ 103 BINARY(Types.BINARY), 104 /** 105 * Identifies the generic SQL type {@code VARBINARY}. 106 */ 107 VARBINARY(Types.VARBINARY), 108 /** 109 * Identifies the generic SQL type {@code LONGVARBINARY}. 110 */ 111 LONGVARBINARY(Types.LONGVARBINARY), 112 /** 113 * Identifies the generic SQL value {@code NULL}. 114 */ 115 NULL(Types.NULL), 116 /** 117 * Indicates that the SQL type 118 * is database-specific and gets mapped to a Java object that can be 119 * accessed via the methods getObject and setObject. 120 */ 121 OTHER(Types.OTHER), 122 /** 123 * Indicates that the SQL type 124 * is database-specific and gets mapped to a Java object that can be 125 * accessed via the methods getObject and setObject. 126 */ 127 JAVA_OBJECT(Types.JAVA_OBJECT), 128 /** 129 * Identifies the generic SQL type {@code DISTINCT}. 130 */ 131 DISTINCT(Types.DISTINCT), 132 /** 133 * Identifies the generic SQL type {@code STRUCT}. 134 */ 135 STRUCT(Types.STRUCT), 136 /** 137 * Identifies the generic SQL type {@code ARRAY}. 138 */ 139 ARRAY(Types.ARRAY), 140 /** 141 * Identifies the generic SQL type {@code BLOB}. 142 */ 143 BLOB(Types.BLOB), 144 /** 145 * Identifies the generic SQL type {@code CLOB}. 146 */ 147 CLOB(Types.CLOB), 148 /** 149 * Identifies the generic SQL type {@code REF}. 150 */ 151 REF(Types.REF), 152 /** 153 * Identifies the generic SQL type {@code DATALINK}. 154 */ 155 DATALINK(Types.DATALINK), 156 /** 157 * Identifies the generic SQL type {@code BOOLEAN}. 158 */ 159 BOOLEAN(Types.BOOLEAN), 160 161 /* JDBC 4.0 Types */ 162 163 /** 164 * Identifies the SQL type {@code ROWID}. 165 */ 166 ROWID(Types.ROWID), 167 /** 168 * Identifies the generic SQL type {@code NCHAR}. 169 */ 170 NCHAR(Types.NCHAR), 171 /** 172 * Identifies the generic SQL type {@code NVARCHAR}. 173 */ 174 NVARCHAR(Types.NVARCHAR), 175 /** 176 * Identifies the generic SQL type {@code LONGNVARCHAR}. 177 */ 178 LONGNVARCHAR(Types.LONGNVARCHAR), 179 /** 180 * Identifies the generic SQL type {@code NCLOB}. 181 */ 182 NCLOB(Types.NCLOB), 183 /** 184 * Identifies the generic SQL type {@code SQLXML}. 185 */ 186 SQLXML(Types.SQLXML), 187 188 /* JDBC 4.2 Types */ 189 190 /** 191 * Identifies the generic SQL type {@code REF_CURSOR}. 192 */ 193 REF_CURSOR(Types.REF_CURSOR), 194 195 /** 196 * Identifies the generic SQL type {@code TIME_WITH_TIMEZONE}. 197 */ 198 TIME_WITH_TIMEZONE(Types.TIME_WITH_TIMEZONE), 199 200 /** 201 * Identifies the generic SQL type {@code TIMESTAMP_WITH_TIMEZONE}. 202 */ 203 TIMESTAMP_WITH_TIMEZONE(Types.TIMESTAMP_WITH_TIMEZONE); 204 205 /** 206 * The Integer value for the JDBCType. It maps to a value in 207 * {@code Types.java} 208 */ 209 private Integer type; 210 211 /** 212 * Constructor to specify the data type value from {@code Types) for 213 * this data type. 214 * @param type The value from {@code Types) for this data type 215 */ 216 JDBCType(final Integer type) { 217 this.type = type; 218 } 219 220 /** 221 *{@inheritDoc } 222 * @return The name of this {@code SQLType}. 223 */ 224 public String getName() { 225 return name(); 226 } 227 /** 228 * Returns the name of the vendor that supports this data type. 229 * @return The name of the vendor for this data type which is 230 * {@literal java.sql} for JDBCType. 231 */ 232 public String getVendor() { 233 return "java.sql"; 234 } 235 236 /** 237 * Returns the vendor specific type number for the data type. 238 * @return An Integer representing the data type. For {@code JDBCType}, 239 * the value will be the same value as in {@code Types} for the data type. 240 */ 241 public Integer getVendorTypeNumber() { 242 return type; 243 } 244 /** 245 * Returns the {@code JDBCType} that corresponds to the specified 246 * {@code Types} value 247 * @param type {@code Types} value 248 * @return The {@code JDBCType} constant 249 * @throws IllegalArgumentException if this enum type has no constant with 250 * the specified {@code Types} value 251 * @see Types 252 */ 253 public static JDBCType valueOf(int type) { 254 for( JDBCType sqlType : JDBCType.class.getEnumConstants()) { 255 if(type == sqlType.type) 256 return sqlType; 257 } 258 throw new IllegalArgumentException("Type:" + type + " is not a valid " 259 + "Types.java value."); 260 } 261} 262