List of usage examples for java.sql Types SMALLINT
int SMALLINT
To view the source code for java.sql Types SMALLINT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type SMALLINT
.
From source file:CSVWriter.java
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: value = handleObject(rs.getObject(colIndex)); break;//from w w w . ja va 2 s . c o m case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); value = Boolean.valueOf(b).toString(); break; case NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: value = handleLong(rs, colIndex); break; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: value = handleBigDecimal(rs.getBigDecimal(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: value = handleInteger(rs, colIndex); break; case Types.DATE: value = handleDate(rs, colIndex); break; case Types.TIME: value = handleTime(rs.getTime(colIndex)); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex)); break; case NVARCHAR: // todo : use rs.getNString case NCHAR: // todo : use rs.getNString case LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:com.openddal.test.BaseTestCase.java
/** * Check if the result set meta data is correct. * * @param rs the result set// ww w .jav a 2s.c o m * @param columnCount the expected column count * @param labels the expected column labels * @param datatypes the expected data types * @param precision the expected precisions * @param scale the expected scales */ protected void assertResultSetMeta(ResultSet rs, int columnCount, String[] labels, int[] datatypes, int[] precision, int[] scale) throws SQLException { ResultSetMetaData meta = rs.getMetaData(); int cc = meta.getColumnCount(); if (cc != columnCount) { fail("result set contains " + cc + " columns not " + columnCount); } for (int i = 0; i < columnCount; i++) { if (labels != null) { String l = meta.getColumnLabel(i + 1); if (!labels[i].equals(l)) { fail("column label " + i + " is " + l + " not " + labels[i]); } } if (datatypes != null) { int t = meta.getColumnType(i + 1); if (datatypes[i] != t) { fail("column datatype " + i + " is " + t + " not " + datatypes[i] + " (prec=" + meta.getPrecision(i + 1) + " scale=" + meta.getScale(i + 1) + ")"); } String typeName = meta.getColumnTypeName(i + 1); String className = meta.getColumnClassName(i + 1); switch (t) { case Types.INTEGER: Assert.assertEquals("INTEGER", typeName); Assert.assertEquals("java.lang.Integer", className); break; case Types.VARCHAR: Assert.assertEquals("VARCHAR", typeName); Assert.assertEquals("java.lang.String", className); break; case Types.SMALLINT: Assert.assertEquals("SMALLINT", typeName); Assert.assertEquals("java.lang.Short", className); break; case Types.TIMESTAMP: Assert.assertEquals("TIMESTAMP", typeName); Assert.assertEquals("java.sql.Timestamp", className); break; case Types.DECIMAL: Assert.assertEquals("DECIMAL", typeName); Assert.assertEquals("java.math.BigDecimal", className); break; default: } } if (precision != null) { int p = meta.getPrecision(i + 1); if (precision[i] != p) { fail("column precision " + i + " is " + p + " not " + precision[i]); } } if (scale != null) { int s = meta.getScale(i + 1); if (scale[i] != s) { fail("column scale " + i + " is " + s + " not " + scale[i]); } } } }
From source file:org.batoo.jpa.core.jdbc.adapter.JdbcAdaptor.java
/** * Returns the data type of the column.// w ww.ja v a 2 s. co m * * @param cd * the column definition * @param sqlType * the sql type * @return the data type * * @since $version * @author hceylan */ protected String getColumnType(AbstractColumn cd, int sqlType) { switch (sqlType) { case Types.BLOB: return "BLOB(" + cd.getLength() + ")"; case Types.CLOB: return "CLOB(" + cd.getLength() + ")"; case Types.VARCHAR: return "VARCHAR(" + cd.getLength() + ")"; case Types.TIME: return "TIME"; case Types.DATE: return "DATE"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.CHAR: return "CHAR"; case Types.BOOLEAN: return "BOOLEAN"; case Types.TINYINT: case Types.SMALLINT: return "SMALLINT"; case Types.INTEGER: return "INTEGER"; case Types.BIGINT: return "BIGINT"; case Types.FLOAT: return "FLOAT" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + ")" : ""); case Types.DOUBLE: return "DOUBLE" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + ")" : ""); case Types.DECIMAL: return "DECIMAL" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + (cd.getScale() > 0 ? "," + cd.getScale() : "") + ")" : ""); } throw new IllegalArgumentException("Unhandled sql type: " + sqlType); }
From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java
protected void setStatementParameter(int parameterIndex, Class<?> parameterType, Object parameterValue, JRPropertiesHolder properties) throws SQLException { if (java.lang.Boolean.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.BIT); } else {// w w w . j a v a 2 s . c om statement.setBoolean(parameterIndex, (Boolean) parameterValue); } } else if (java.lang.Byte.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.TINYINT); } else { statement.setByte(parameterIndex, (Byte) parameterValue); } } else if (java.lang.Double.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.DOUBLE); } else { statement.setDouble(parameterIndex, (Double) parameterValue); } } else if (java.lang.Float.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.FLOAT); } else { statement.setFloat(parameterIndex, (Float) parameterValue); } } else if (java.lang.Integer.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.INTEGER); } else { statement.setInt(parameterIndex, (Integer) parameterValue); } } else if (java.lang.Long.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.BIGINT); } else { statement.setLong(parameterIndex, (Long) parameterValue); } } else if (java.lang.Short.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.SMALLINT); } else { statement.setShort(parameterIndex, (Short) parameterValue); } } else if (java.math.BigDecimal.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.DECIMAL); } else { statement.setBigDecimal(parameterIndex, (BigDecimal) parameterValue); } } else if (java.lang.String.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.VARCHAR); } else { statement.setString(parameterIndex, parameterValue.toString()); } } else if (java.sql.Timestamp.class.isAssignableFrom(parameterType)) { setTimestamp(parameterIndex, parameterValue, properties); } else if (java.sql.Time.class.isAssignableFrom(parameterType)) { setTime(parameterIndex, parameterValue, properties); } else if (java.util.Date.class.isAssignableFrom(parameterType)) { setDate(parameterIndex, parameterValue, properties); } else { if (isProcedureCall) { boolean handled = procedureCallHandler.setParameterValue(parameterIndex, parameterType, parameterValue); if (handled) { return; } } if (parameterValue == null) { statement.setNull(parameterIndex, Types.JAVA_OBJECT); } else { statement.setObject(parameterIndex, parameterValue); } } }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWISOLanguageTable.java
public CFCrmISOLanguageBuff[] readBuffByCountryIdx(CFCrmAuthorization Authorization, Short ISOCountryId) { final String S_ProcName = "readBuffByCountryIdx"; ResultSet resultSet = null;/*from w w w. j a v a 2 s . c om*/ try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_iso_lang_by_countryidx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtReadBuffByCountryIdx == null) { stmtReadBuffByCountryIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByCountryIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByCountryIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); if (ISOCountryId != null) { stmtReadBuffByCountryIdx.setShort(argIdx++, ISOCountryId.shortValue()); } else { stmtReadBuffByCountryIdx.setNull(argIdx++, java.sql.Types.SMALLINT); } resultSet = stmtReadBuffByCountryIdx.executeQuery(); List<CFCrmISOLanguageBuff> buffList = new LinkedList<CFCrmISOLanguageBuff>(); while (resultSet.next()) { CFCrmISOLanguageBuff buff = unpackISOLanguageResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFCrmISOLanguageBuff[] retBuff = new CFCrmISOLanguageBuff[buffList.size()]; Iterator<CFCrmISOLanguageBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:com.squid.kraken.v4.caching.redis.datastruct.RawMatrix.java
public static String getJavaDatatype(int colType) { switch (colType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return "java.lang.String"; case Types.NUMERIC: case Types.DECIMAL: return "java.math.BigDecimal"; case Types.BIT: return "boolean"; case Types.TINYINT: return "byte"; case Types.SMALLINT: return "short"; case Types.INTEGER: return "int"; case Types.BIGINT: return "long"; case Types.REAL: return "float"; case Types.FLOAT: case Types.DOUBLE: return "double"; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return "byte[]"; case Types.DATE: return "java.sql.Date"; case Types.TIME: return "java.sql.Time"; case Types.TIMESTAMP: return "java.sql.Timestamp"; case Types.OTHER: return "java.lang.Object"; default:/*ww w.j a v a 2 s . c om*/ return null; } }
From source file:org.jumpmind.symmetric.db.ase.AseTriggerTemplate.java
@Override protected String buildKeyVariablesDeclare(Column[] columns, String prefix) { String text = ""; for (int i = 0; i < columns.length; i++) { text += "declare @" + prefix + "pk" + i + " "; switch (columns[i].getMappedTypeCode()) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: // ASE does not support bigint text += "NUMERIC(18,0)\n"; break; case Types.NUMERIC: case Types.DECIMAL: // Use same default scale and precision used by Sybase ASA // for a decimal with unspecified scale and precision. text += "decimal(30,6)\n"; break; case Types.FLOAT: case Types.REAL: case Types.DOUBLE: text += "float\n"; break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: text += "varchar(1000)\n"; break; case Types.DATE: text += "date\n"; break; case Types.TIME: text += "time\n"; break; case Types.TIMESTAMP: text += "datetime\n"; break; case Types.BOOLEAN: case Types.BIT: text += "bit\n"; break; case Types.CLOB: text += "varchar(32767)\n"; break; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case -10: // SQL-Server ntext binary type text += "varbinary(32767)\n"; break; case Types.OTHER: text += "varbinary(32767)\n"; break; default://w w w. ja v a 2 s .c o m if (columns[i].getJdbcTypeName() != null && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) { text += "interval"; break; } throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType()); } } return text; }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetSybase.CFInternetSybaseISOLanguageTable.java
public CFInternetISOLanguageBuff[] readBuffByCountryIdx(CFInternetAuthorization Authorization, Short ISOCountryId) {//from ww w. j a v a 2 s . com final String S_ProcName = "readBuffByCountryIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "exec sp_read_iso_lang_by_countryidx ?, ?, ?, ?, ?" + ", " + "?"; if (stmtReadBuffByCountryIdx == null) { stmtReadBuffByCountryIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByCountryIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByCountryIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); if (ISOCountryId != null) { stmtReadBuffByCountryIdx.setShort(argIdx++, ISOCountryId.shortValue()); } else { stmtReadBuffByCountryIdx.setNull(argIdx++, java.sql.Types.SMALLINT); } resultSet = stmtReadBuffByCountryIdx.executeQuery(); List<CFInternetISOLanguageBuff> buffList = new LinkedList<CFInternetISOLanguageBuff>(); while (resultSet.next()) { CFInternetISOLanguageBuff buff = unpackISOLanguageResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFInternetISOLanguageBuff[] retBuff = new CFInternetISOLanguageBuff[buffList.size()]; Iterator<CFInternetISOLanguageBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetDb2LUW.CFInternetDb2LUWISOLanguageTable.java
public CFInternetISOLanguageBuff[] readBuffByCountryIdx(CFInternetAuthorization Authorization, Short ISOCountryId) {/*w ww . j a v a 2s . c o m*/ final String S_ProcName = "readBuffByCountryIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_iso_lang_by_countryidx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtReadBuffByCountryIdx == null) { stmtReadBuffByCountryIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByCountryIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByCountryIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); if (ISOCountryId != null) { stmtReadBuffByCountryIdx.setShort(argIdx++, ISOCountryId.shortValue()); } else { stmtReadBuffByCountryIdx.setNull(argIdx++, java.sql.Types.SMALLINT); } resultSet = stmtReadBuffByCountryIdx.executeQuery(); List<CFInternetISOLanguageBuff> buffList = new LinkedList<CFInternetISOLanguageBuff>(); while (resultSet.next()) { CFInternetISOLanguageBuff buff = unpackISOLanguageResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFInternetISOLanguageBuff[] retBuff = new CFInternetISOLanguageBuff[buffList.size()]; Iterator<CFInternetISOLanguageBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetPgSql.CFInternetPgSqlISOLanguageTable.java
public CFInternetISOLanguageBuff[] readBuffByCountryIdx(CFInternetAuthorization Authorization, Short ISOCountryId) {/* www. j a v a2 s.c o m*/ final String S_ProcName = "readBuffByCountryIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "SELECT * FROM " + schema.getLowerDbSchemaName() + ".sp_read_iso_lang_by_countryidx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtReadBuffByCountryIdx == null) { stmtReadBuffByCountryIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByCountryIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByCountryIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByCountryIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); if (ISOCountryId != null) { stmtReadBuffByCountryIdx.setShort(argIdx++, ISOCountryId.shortValue()); } else { stmtReadBuffByCountryIdx.setNull(argIdx++, java.sql.Types.SMALLINT); } resultSet = stmtReadBuffByCountryIdx.executeQuery(); List<CFInternetISOLanguageBuff> buffList = new LinkedList<CFInternetISOLanguageBuff>(); while (resultSet.next()) { CFInternetISOLanguageBuff buff = unpackISOLanguageResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFInternetISOLanguageBuff[] retBuff = new CFInternetISOLanguageBuff[buffList.size()]; Iterator<CFInternetISOLanguageBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }