本文整理汇总了Java中java.sql.Types.SMALLINT属性的典型用法代码示例。如果您正苦于以下问题:Java Types.SMALLINT属性的具体用法?Java Types.SMALLINT怎么用?Java Types.SMALLINT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.sql.Types
的用法示例。
在下文中一共展示了Types.SMALLINT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isDecimalType
/**
* Checks if the SQL Type is a Decimal/Number Type
*
* @param type
* SQL Type
*/
private static final boolean isDecimalType(int type) {
switch (type) {
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
case Types.NUMERIC:
case Types.DECIMAL:
return true;
}
return false;
}
示例2: createFkMetadataFields
protected Field[] createFkMetadataFields() {
Field[] fields = new Field[14];
fields[0] = new Field("", "PKTABLE_CAT", Types.CHAR, 255);
fields[1] = new Field("", "PKTABLE_SCHEM", Types.CHAR, 0);
fields[2] = new Field("", "PKTABLE_NAME", Types.CHAR, 255);
fields[3] = new Field("", "PKCOLUMN_NAME", Types.CHAR, 32);
fields[4] = new Field("", "FKTABLE_CAT", Types.CHAR, 255);
fields[5] = new Field("", "FKTABLE_SCHEM", Types.CHAR, 0);
fields[6] = new Field("", "FKTABLE_NAME", Types.CHAR, 255);
fields[7] = new Field("", "FKCOLUMN_NAME", Types.CHAR, 32);
fields[8] = new Field("", "KEY_SEQ", Types.SMALLINT, 2);
fields[9] = new Field("", "UPDATE_RULE", Types.SMALLINT, 2);
fields[10] = new Field("", "DELETE_RULE", Types.SMALLINT, 2);
fields[11] = new Field("", "FK_NAME", Types.CHAR, 0);
fields[12] = new Field("", "PK_NAME", Types.CHAR, 0);
fields[13] = new Field("", "DEFERRABILITY", Types.SMALLINT, 2);
return fields;
}
示例3: createProcedureColumnsFields
protected Field[] createProcedureColumnsFields() {
Field[] fields = new Field[20];
fields[0] = new Field("", "PROCEDURE_CAT", Types.CHAR, 512);
fields[1] = new Field("", "PROCEDURE_SCHEM", Types.CHAR, 512);
fields[2] = new Field("", "PROCEDURE_NAME", Types.CHAR, 512);
fields[3] = new Field("", "COLUMN_NAME", Types.CHAR, 512);
fields[4] = new Field("", "COLUMN_TYPE", Types.CHAR, 64);
fields[5] = new Field("", "DATA_TYPE", Types.SMALLINT, 6);
fields[6] = new Field("", "TYPE_NAME", Types.CHAR, 64);
fields[7] = new Field("", "PRECISION", Types.INTEGER, 12);
fields[8] = new Field("", "LENGTH", Types.INTEGER, 12);
fields[9] = new Field("", "SCALE", Types.SMALLINT, 12);
fields[10] = new Field("", "RADIX", Types.SMALLINT, 6);
fields[11] = new Field("", "NULLABLE", Types.SMALLINT, 6);
fields[12] = new Field("", "REMARKS", Types.CHAR, 512);
fields[13] = new Field("", "COLUMN_DEF", Types.CHAR, 512);
fields[14] = new Field("", "SQL_DATA_TYPE", Types.INTEGER, 12);
fields[15] = new Field("", "SQL_DATETIME_SUB", Types.INTEGER, 12);
fields[16] = new Field("", "CHAR_OCTET_LENGTH", Types.INTEGER, 12);
fields[17] = new Field("", "ORDINAL_POSITION", Types.INTEGER, 12);
fields[18] = new Field("", "IS_NULLABLE", Types.CHAR, 512);
fields[19] = new Field("", "SPECIFIC_NAME", Types.CHAR, 512);
return fields;
}
示例4: createColumnsFields
protected Field[] createColumnsFields() {
Field[] fields = new Field[24];
fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 255);
fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 0);
fields[2] = new Field("", "TABLE_NAME", Types.CHAR, 255);
fields[3] = new Field("", "COLUMN_NAME", Types.CHAR, 32);
fields[4] = new Field("", "DATA_TYPE", Types.INTEGER, 5);
fields[5] = new Field("", "TYPE_NAME", Types.CHAR, 16);
fields[6] = new Field("", "COLUMN_SIZE", Types.INTEGER, Integer.toString(Integer.MAX_VALUE).length());
fields[7] = new Field("", "BUFFER_LENGTH", Types.INTEGER, 10);
fields[8] = new Field("", "DECIMAL_DIGITS", Types.INTEGER, 10);
fields[9] = new Field("", "NUM_PREC_RADIX", Types.INTEGER, 10);
fields[10] = new Field("", "NULLABLE", Types.INTEGER, 10);
fields[11] = new Field("", "REMARKS", Types.CHAR, 0);
fields[12] = new Field("", "COLUMN_DEF", Types.CHAR, 0);
fields[13] = new Field("", "SQL_DATA_TYPE", Types.INTEGER, 10);
fields[14] = new Field("", "SQL_DATETIME_SUB", Types.INTEGER, 10);
fields[15] = new Field("", "CHAR_OCTET_LENGTH", Types.INTEGER, Integer.toString(Integer.MAX_VALUE).length());
fields[16] = new Field("", "ORDINAL_POSITION", Types.INTEGER, 10);
fields[17] = new Field("", "IS_NULLABLE", Types.CHAR, 3);
fields[18] = new Field("", "SCOPE_CATALOG", Types.CHAR, 255);
fields[19] = new Field("", "SCOPE_SCHEMA", Types.CHAR, 255);
fields[20] = new Field("", "SCOPE_TABLE", Types.CHAR, 255);
fields[21] = new Field("", "SOURCE_DATA_TYPE", Types.SMALLINT, 10);
fields[22] = new Field("", "IS_AUTOINCREMENT", Types.CHAR, 3); // JDBC 4
fields[23] = new Field("", "IS_GENERATEDCOLUMN", Types.CHAR, 3); // JDBC 4.1
return fields;
}
示例5: isPrecisionRequired
public static boolean isPrecisionRequired(int jdbcType) {
switch (jdbcType) {
case Types.BIGINT:
case Types.BOOLEAN:
case Types.INTEGER:
case Types.SMALLINT:
case Types.TINYINT:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
case Types.DATE:
case Types.TIMESTAMP:
case Types.JAVA_OBJECT:
case Types.LONGVARCHAR:
case Types.LONGVARBINARY:
case Types.BLOB:
case Types.CLOB:
case Types.ARRAY:
case Types.STRUCT:
case Types.DISTINCT:
case Types.REF:
case Types.DATALINK:
return false;
default:
return true;
}
}
示例6: testBug25894
public void testBug25894() throws Exception {
createTable("bug25894",
"(tinyInt_type TINYINT DEFAULT 1, tinyIntU_type TINYINT UNSIGNED DEFAULT 1, smallInt_type SMALLINT DEFAULT 1,"
+ "smallIntU_type SMALLINT UNSIGNED DEFAULT 1, mediumInt_type MEDIUMINT DEFAULT 1, mediumIntU_type MEDIUMINT UNSIGNED DEFAULT 1,"
+ "int_type INT DEFAULT 1, intU_type INT UNSIGNED DEFAULT 1, bigInt_type BIGINT DEFAULT 1, bigIntU_type BIGINT UNSIGNED DEFAULT 1);");
this.stmt.executeUpdate("INSERT INTO bug25894 VALUES (-1,1,-1,1,-1,1,-1,1,-1,1)");
this.rs = this.stmt.executeQuery("SELECT * FROM bug25894");
java.sql.ResultSetMetaData tblMD = this.rs.getMetaData();
this.rs.first();
for (int i = 1; i < tblMD.getColumnCount() + 1; i++) {
String typesName = "";
switch (tblMD.getColumnType(i)) {
case Types.INTEGER:
typesName = "Types.INTEGER";
break;
case Types.TINYINT:
typesName = "Types.TINYINT";
break;
case Types.BIGINT:
typesName = "Types.BIGINT";
break;
case Types.SMALLINT:
typesName = "Types.SMALLINT";
break;
}
System.out.println(i + " .fld: " + tblMD.getColumnName(i) + "T: " + typesName + ", MDC: " + tblMD.getColumnClassName(i) + " "
+ tblMD.getColumnTypeName(i) + " , getObj: " + this.rs.getObject(i).getClass());
}
}
示例7: isCaseSensitive
/**
* Does a column's case matter?
*
* @param column
* the first column is 1, the second is 2...
*
* @return true if so
*
* @throws java.sql.SQLException
* if a database access error occurs
*/
public boolean isCaseSensitive(int column) throws java.sql.SQLException {
Field field = getField(column);
int sqlType = field.getSQLType();
switch (sqlType) {
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
return false;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
if (field.isBinary()) {
return true;
}
String collationName = field.getCollation();
return ((collationName != null) && !collationName.endsWith("_ci"));
default:
return true;
}
}
示例8: isIntValue
public boolean isIntValue() {
if(this.dataType==Types.INTEGER || this.dataType==Types.SMALLINT)
{
return true;
}
else
{
return false;
}
}
示例9: createFieldMetadataForGetProcedures
protected Field[] createFieldMetadataForGetProcedures() {
Field[] fields = new Field[9];
fields[0] = new Field("", "PROCEDURE_CAT", Types.CHAR, 255);
fields[1] = new Field("", "PROCEDURE_SCHEM", Types.CHAR, 255);
fields[2] = new Field("", "PROCEDURE_NAME", Types.CHAR, 255);
fields[3] = new Field("", "reserved1", Types.CHAR, 0);
fields[4] = new Field("", "reserved2", Types.CHAR, 0);
fields[5] = new Field("", "reserved3", Types.CHAR, 0);
fields[6] = new Field("", "REMARKS", Types.CHAR, 255);
fields[7] = new Field("", "PROCEDURE_TYPE", Types.SMALLINT, 6);
fields[8] = new Field("", "SPECIFIC_NAME", Types.CHAR, 255);
return fields;
}
示例10: castValue
/**
* For the given string representation of a value, convert it to the proper
* object based on its sqlType
* @param sqlType
* @param value
* @return
* @see java.sql.Types
*/
public static Object castValue(int sqlType, String value) {
Object ret = null;
switch (sqlType) {
case Types.CHAR:
case Types.VARCHAR:
case Types.NCHAR:
case Types.NVARCHAR: {
ret = value;
break;
}
case Types.TINYINT:
case Types.SMALLINT: {
ret = Short.parseShort(value);
break;
}
case Types.INTEGER: {
ret = Integer.parseInt(value);
break;
}
case Types.BIGINT: {
ret = Long.parseLong(value);
break;
}
case Types.BOOLEAN: {
ret = Boolean.parseBoolean(value);
break;
}
case Types.DECIMAL:
case Types.DOUBLE: {
ret = Double.parseDouble(value);
break;
}
case Types.FLOAT: {
ret = Float.parseFloat(value);
break;
}
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP: {
for (DateFormat f : timestamp_formats) {
try {
ret = f.parse(value);
} catch (ParseException ex) {
// Ignore...
}
if (ret != null) break;
} // FOR
if (ret == null) throw new RuntimeException("Failed to parse timestamp '" + value + "'");
break;
}
default:
LOG.warn("Unexpected SQL Type '" + sqlType + "' for value '" + value + "'");
} // SWITCH
return (ret);
}
示例11: makeDbColDefinition
public BaseDbColDefinition makeDbColDefinition()
{
BaseDbColDefinition dbColDef = null;
if(m_nTypeId == Types.CHAR)
{
dbColDef = new DbColDefinitionChar(this);
}
else if(m_nTypeId == Types.DECIMAL) // Unsupported type in jlib, but supported in nacaRT
{
dbColDef = new DbColDefinitionDecimal(this);
}
else if(m_nTypeId == Types.TIME)
{
dbColDef = new DbColDefinitionTime(this);
}
else if(m_nTypeId == Types.TIMESTAMP)
{
dbColDef = new DbColDefinitionTimestamp(this);
}
else if(m_nTypeId == Types.DATE)
{
dbColDef = new DbColDefinitionDate(this);
}
else if(m_nTypeId == Types.VARCHAR)
{
dbColDef = new DbColDefinitionVarchar(this);
}
else if(m_nTypeId == Types.LONGVARCHAR)
{
dbColDef = new DbColDefinitionLongVarchar(this);
}
else if(m_nTypeId == Types.SMALLINT)
{
dbColDef = new DbColDefinitionSmallint(this);
}
else if(m_nTypeId == Types.INTEGER)
{
dbColDef = new DbColDefinitionInteger(this);
}
else if(m_nTypeId == Types.DOUBLE)
{
dbColDef = new DbColDefinitionDouble(this);
}
return dbColDef;
}
示例12: setParamValue
private void setParamValue(PreparedStatement ps, int psIdx, ResultSetRow row, int rsIdx, int sqlType) throws SQLException {
byte[] val = row.getColumnValue(rsIdx);
if (val == null) {
ps.setNull(psIdx, Types.NULL);
return;
}
switch (sqlType) {
case Types.NULL:
ps.setNull(psIdx, Types.NULL);
break;
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
ps.setInt(psIdx, row.getInt(rsIdx));
break;
case Types.BIGINT:
ps.setLong(psIdx, row.getLong(rsIdx));
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.DECIMAL:
case Types.NUMERIC:
ps.setString(psIdx, row.getString(rsIdx, this.charEncoding, this.connection));
break;
case Types.DATE:
ps.setDate(psIdx, row.getDateFast(rsIdx, this.connection, this, this.fastDefaultCal), this.fastDefaultCal);
break;
case Types.TIMESTAMP:
ps.setTimestamp(psIdx, row.getTimestampFast(rsIdx, this.fastDefaultCal, this.connection.getDefaultTimeZone(), false, this.connection, this));
break;
case Types.TIME:
ps.setTime(psIdx, row.getTimeFast(rsIdx, this.fastDefaultCal, this.connection.getDefaultTimeZone(), false, this.connection, this));
break;
case Types.FLOAT:
case Types.DOUBLE:
case Types.REAL:
case Types.BOOLEAN:
ps.setBytesNoEscapeNoQuotes(psIdx, val);
break;
/*
* default, but also explicitly for following types:
* case Types.BINARY:
* case Types.BLOB:
*/
default:
ps.setBytes(psIdx, val);
break;
}
}
示例13: getSqlTypeString
/**
* 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
}
}
示例14: fakeParameterTypes
/**
* Used to fake up some metadata when we don't have access to
* SHOW CREATE PROCEDURE or mysql.proc.
*
* @throws SQLException
* if we can't build the metadata.
*/
private void fakeParameterTypes(boolean isReallyProcedure) throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
Field[] fields = new Field[13];
fields[0] = new Field("", "PROCEDURE_CAT", Types.CHAR, 0);
fields[1] = new Field("", "PROCEDURE_SCHEM", Types.CHAR, 0);
fields[2] = new Field("", "PROCEDURE_NAME", Types.CHAR, 0);
fields[3] = new Field("", "COLUMN_NAME", Types.CHAR, 0);
fields[4] = new Field("", "COLUMN_TYPE", Types.CHAR, 0);
fields[5] = new Field("", "DATA_TYPE", Types.SMALLINT, 0);
fields[6] = new Field("", "TYPE_NAME", Types.CHAR, 0);
fields[7] = new Field("", "PRECISION", Types.INTEGER, 0);
fields[8] = new Field("", "LENGTH", Types.INTEGER, 0);
fields[9] = new Field("", "SCALE", Types.SMALLINT, 0);
fields[10] = new Field("", "RADIX", Types.SMALLINT, 0);
fields[11] = new Field("", "NULLABLE", Types.SMALLINT, 0);
fields[12] = new Field("", "REMARKS", Types.CHAR, 0);
String procName = isReallyProcedure ? extractProcedureName() : null;
byte[] procNameAsBytes = null;
try {
procNameAsBytes = procName == null ? null : StringUtils.getBytes(procName, "UTF-8");
} catch (UnsupportedEncodingException ueEx) {
procNameAsBytes = StringUtils.s2b(procName, this.connection);
}
ArrayList<ResultSetRow> resultRows = new ArrayList<ResultSetRow>();
for (int i = 0; i < this.parameterCount; i++) {
byte[][] row = new byte[13][];
row[0] = null; // PROCEDURE_CAT
row[1] = null; // PROCEDURE_SCHEM
row[2] = procNameAsBytes; // PROCEDURE/NAME
row[3] = StringUtils.s2b(String.valueOf(i), this.connection); // COLUMN_NAME
row[4] = StringUtils.s2b(String.valueOf(java.sql.DatabaseMetaData.procedureColumnIn), this.connection);
row[5] = StringUtils.s2b(String.valueOf(Types.VARCHAR), this.connection); // DATA_TYPE
row[6] = StringUtils.s2b("VARCHAR", this.connection); // TYPE_NAME
row[7] = StringUtils.s2b(Integer.toString(65535), this.connection); // PRECISION
row[8] = StringUtils.s2b(Integer.toString(65535), this.connection); // LENGTH
row[9] = StringUtils.s2b(Integer.toString(0), this.connection); // SCALE
row[10] = StringUtils.s2b(Integer.toString(10), this.connection); // RADIX
row[11] = StringUtils.s2b(Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown), this.connection); // nullable
row[12] = null;
resultRows.add(new ByteArrayRow(row, getExceptionInterceptor()));
}
java.sql.ResultSet paramTypesRs = DatabaseMetaData.buildResultSet(fields, resultRows, this.connection);
convertGetProcedureColumnsToInternalDescriptors(paramTypesRs);
}
}
示例15: javaTypeMysql
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;
}
}