List of usage examples for java.sql Types BIT
int BIT
To view the source code for java.sql Types BIT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIT
.
From source file:org.apache.syncope.core.persistence.jpa.content.ContentLoaderHandler.java
private Object[] getParameters(final String tableName, final Attributes attrs) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); Map<String, Integer> colTypes = jdbcTemplate.query("SELECT * FROM " + tableName + " WHERE 0=1", new ResultSetExtractor<Map<String, Integer>>() { @Override/*from www . jav a 2s .c o m*/ public Map<String, Integer> extractData(final ResultSet rs) throws SQLException { Map<String, Integer> colTypes = new HashMap<>(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { colTypes.put(rs.getMetaData().getColumnName(i).toUpperCase(), rs.getMetaData().getColumnType(i)); } return colTypes; } }); Object[] parameters = new Object[attrs.getLength()]; for (int i = 0; i < attrs.getLength(); i++) { Integer colType = colTypes.get(attrs.getQName(i).toUpperCase()); if (colType == null) { LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase()); colType = Types.VARCHAR; } switch (colType) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: try { parameters[i] = Integer.valueOf(attrs.getValue(i)); } catch (NumberFormatException e) { LOG.error("Unparsable Integer '{}'", attrs.getValue(i)); parameters[i] = attrs.getValue(i); } break; case Types.NUMERIC: case Types.DECIMAL: case Types.BIGINT: try { parameters[i] = Long.valueOf(attrs.getValue(i)); } catch (NumberFormatException e) { LOG.error("Unparsable Long '{}'", attrs.getValue(i)); parameters[i] = attrs.getValue(i); } break; case Types.DOUBLE: try { parameters[i] = Double.valueOf(attrs.getValue(i)); } catch (NumberFormatException e) { LOG.error("Unparsable Double '{}'", attrs.getValue(i)); parameters[i] = attrs.getValue(i); } break; case Types.REAL: case Types.FLOAT: try { parameters[i] = Float.valueOf(attrs.getValue(i)); } catch (NumberFormatException e) { LOG.error("Unparsable Float '{}'", attrs.getValue(i)); parameters[i] = attrs.getValue(i); } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: try { parameters[i] = FormatUtils.parseDate(attrs.getValue(i)); } catch (ParseException e) { LOG.error("Unparsable Date '{}'", attrs.getValue(i)); parameters[i] = attrs.getValue(i); } break; case Types.BIT: case Types.BOOLEAN: parameters[i] = "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: try { parameters[i] = Hex.decodeHex(attrs.getValue(i).toCharArray()); } catch (DecoderException | IllegalArgumentException e) { parameters[i] = attrs.getValue(i); } break; case Types.BLOB: try { parameters[i] = Hex.decodeHex(attrs.getValue(i).toCharArray()); } catch (DecoderException | IllegalArgumentException e) { LOG.warn("Error decoding hex string to specify a blob parameter", e); parameters[i] = attrs.getValue(i); } catch (Exception e) { LOG.warn("Error creating a new blob parameter", e); } break; default: parameters[i] = attrs.getValue(i); } } return parameters; }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override public boolean isAllowedConversion(int expected, int actual, String actualName, int actualSize) { // Oracle internal conversions if (expected == Types.DOUBLE && actual == Types.FLOAT) { return true; }//from w ww. j av a2 s.c o m if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NVARCHAR2")) { return true; } if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NCLOB")) { return true; } if (expected == Types.BIT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 1) { return true; } if (expected == Types.TINYINT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 3) { return true; } if (expected == Types.INTEGER && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 10) { return true; } if (expected == Types.BIGINT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 19) { return true; } // CLOB vs VARCHAR compatibility if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NCLOB")) { return true; } if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NVARCHAR2")) { return true; } return false; }
From source file:com.netspective.axiom.sql.QueryResultSet.java
public void fillReportFromMetaData(TabularReport report) throws SQLException { ResultSetMetaData rsmd = resultSet.getMetaData(); int numColumns = rsmd.getColumnCount(); TabularReportColumns columns = report.getColumns(); columns.clear();//w ww.jav a 2 s .c o m for (int c = 1; c <= numColumns; c++) { TabularReportColumn column = null; int dataType = rsmd.getColumnType(c); switch (dataType) { case Types.INTEGER: case Types.SMALLINT: case Types.BIGINT: case Types.TINYINT: case Types.BIT: column = new NumericColumn(); break; case Types.FLOAT: case Types.REAL: column = new DecimalColumn(); break; case Types.NUMERIC: case Types.DECIMAL: if (rsmd.getScale(c) > 0) column = new DecimalColumn(); else column = new NumericColumn(); break; default: column = new GeneralColumn(); break; } column.setColIndex(c - 1); column.setHeading(new StaticValueSource( TextUtils.getInstance().sqlIdentifierToText(rsmd.getColumnLabel(c), true))); column.setDataType(dataType); column.setWidth(rsmd.getColumnDisplaySize(c)); columns.add(column); } report.finalizeContents(); }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectDB2.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: return getFromResultSetString(rs, index, column); case Types.BIT: return rs.getBoolean(index); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: return getFromResultSetTimestamp(rs, index, column); }/* w w w .ja va 2 s .c o m*/ throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the java type for the given SQL type from {@link Types}. *//*from ww w. j av a2 s. co m*/ public static Class<?> getJavaType(int type, int size, int decimals) { switch (type) { case Types.CHAR: if (size == 1) return char.class; // no break case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: return String.class; case Types.BIT: return boolean.class; case Types.TINYINT: return byte.class; case Types.SMALLINT: return short.class; case Types.INTEGER: return int.class; case Types.BIGINT: return long.class; case Types.REAL: case Types.FLOAT: return float.class; case Types.DOUBLE: case Types.NUMERIC: return double.class; case Types.DECIMAL: // oracle uses this for everything, so look at size and decimals if (decimals == 0 && size < 10) return int.class; else if (decimals == 0) return long.class; return double.class; // ### return a BigDecimal if the size if out of double range? case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return Date.class; default: return Object.class; } }
From source file:org.apache.sqoop.manager.ConnManager.java
/** * Resolve a database-specific type to Avro data type. * @param sqlType sql type// ww w . ja va 2 s.com * @return avro type */ public Type toAvroType(int sqlType) { switch (sqlType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return Type.INT; case Types.BIGINT: return Type.LONG; case Types.BIT: case Types.BOOLEAN: return Type.BOOLEAN; case Types.REAL: return Type.FLOAT; case Types.FLOAT: case Types.DOUBLE: return Type.DOUBLE; case Types.NUMERIC: case Types.DECIMAL: return Type.STRING; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NVARCHAR: case Types.NCHAR: return Type.STRING; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return Type.STRING; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return Type.BYTES; default: throw new IllegalArgumentException("Cannot convert SQL type " + sqlType); } }
From source file:org.jumpmind.symmetric.service.impl.AbstractDataExtractorServiceTest.java
protected void save(TestExtract obj) { String updateSql = String.format( "update %s set varchar_value=?, longvarchar_value=?, timestamp_value=?, date_value=?, bit_value=?, bigint_value=?, decimal_value=? where id=?", TEST_TABLE);/* www.j a va2 s . c om*/ String insertSql = String.format( "insert into %s (varchar_value, longvarchar_value, timestamp_value, date_value, bit_value, bigint_value, decimal_value, id) values(?,?,?,?,?,?,?,?)", TEST_TABLE); if (0 == getSqlTemplate().update(updateSql, new Object[] { obj.getVarcharValue(), obj.getLongVarcharValue(), obj.getTimestampValue(), obj.getDateValue(), obj.isBitValue(), obj.getBigIntValue(), obj.getDecimalValue(), obj.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.DATE, Types.BIT, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC })) { getSqlTemplate().update(insertSql, new Object[] { obj.getVarcharValue(), obj.getLongVarcharValue(), obj.getTimestampValue(), obj.getDateValue(), obj.isBitValue(), obj.getBigIntValue(), obj.getDecimalValue(), obj.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.DATE, Types.BIT, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC }); } }
From source file:org.apache.ddlutils.platform.mssql.MSSqlBuilder.java
/** * {@inheritDoc}/*from www .j ava2 s . c om*/ */ protected String getNativeDefaultValue(Column column) { // Sql Server wants BIT default values as 0 or 1 if ((column.getTypeCode() == Types.BIT) || (column.getTypeCode() == Types.BOOLEAN)) { return getDefaultValueHelper().convert(column.getDefaultValue(), column.getTypeCode(), Types.SMALLINT); } else { return super.getNativeDefaultValue(column); } }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectPostgreSQL.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: String v;//from w w w . j av a 2 s.co m if (column.getType() == ColumnType.BLOBID) { v = ((Binary) value).getDigest(); } else { v = (String) value; } ps.setString(index, v); break; case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); return; case Types.SMALLINT: ps.setInt(index, ((Long) value).intValue()); return; case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Long) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: Calendar cal = (Calendar) value; Timestamp ts = new Timestamp(cal.getTimeInMillis()); ps.setTimestamp(index, ts, cal); // cal passed for timezone return; case Types.ARRAY: Array array = createArrayOf(Types.VARCHAR, (Object[]) value, ps.getConnection()); ps.setArray(index, array); return; case Types.OTHER: if (column.getType() == ColumnType.FTSTORED) { ps.setString(index, (String) value); return; } throw new SQLException("Unhandled type: " + column.getType()); default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }