List of usage examples for java.sql Types BOOLEAN
int BOOLEAN
To view the source code for java.sql Types BOOLEAN.
Click Source Link
BOOLEAN
. From source file:com.tesora.dve.common.TestDataGenerator.java
protected Object getColumnValue(ColumnMetadata cm) { Object cv = null;/*from w w w . j a va 2 s . co m*/ Calendar cal = Calendar.getInstance(); switch (cm.getDataType()) { case Types.BIT: case Types.BOOLEAN: cv = Boolean.TRUE; break; case Types.BIGINT: cv = Long.MAX_VALUE; break; case Types.CHAR: case Types.VARCHAR: cv = StringUtils.left(baseString, cm.getSize()); break; case Types.SMALLINT: cv = Short.MAX_VALUE; break; case Types.TINYINT: cv = Byte.MAX_VALUE; break; case Types.INTEGER: cv = Integer.MAX_VALUE; break; case Types.DOUBLE: cv = new Double(1234.5678); // TODO need to handle s,p break; case Types.FLOAT: cv = new Float(123.56); // TODO need to handle s,p break; case Types.DECIMAL: cv = new BigDecimal("12345.6789"); // TODO need to handle s,p break; case Types.DATE: cal.setTimeInMillis(123456789); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cv = cal.getTime(); break; case Types.TIMESTAMP: cal.setTimeInMillis(123456789); cv = cal.getTime(); break; case Types.TIME: cv = new Time(123456789); break; default: break; } return cv; }
From source file:konditer_reorganized_database.dao.CakeDao.java
@Override public void addCake(int cakeId, int customerId, double cakePrice, int orderId, String cakeName, double cakeWeight, String cakePhoto, String cakeKeywords, boolean cakeStatus) throws DataAccessException { String SQL_QUERY = "INSERT INTO cakes ( CAKE_ID, " + "CUSTOMER_ID, " + "CAKE_PRICE, " + "ORDER_ID, " + "CAKE_NAME, " + "CAKE_WEIGHT, " + "CAKE_PHOTO_MINI, " + "CAKE_PHOTO_MAXI, " + "CAKE_KEYWORDS, " + "CAKE_STATUS ) " + "VALUES (?,?,?,?,?,?,?,?,?,?)"; //int cakeId1 = genIdDao.getCakeId(); /*/*from ww w .j a v a 2s .c o m*/ ??? ??? 2- ? ?? ? */ //try{ int rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { cakeId, customerId, cakePrice, orderId, cakeName, cakeWeight, "" + cakeId + "_s.jpg", "" + cakeId + ".jpg", cakeKeywords, cakeStatus }, new int[] { Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.DOUBLE, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN }); Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, " : {0} .", rowCount); //}catch(DataAccessException e){ // Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, ". ."); //genIdDao.decrementCakeId(); //} }
From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java
public String formatJDBCObject(final Object jdbcObject, final int colType) throws SQLException { String value = ""; switch (colType) { case Types.BIT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); }/* w w w.j av a 2 s . c o m*/ break; case Types.BOOLEAN: if (jdbcObject != null) { value = new Boolean(jdbcObject.toString()).toString(); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.CLOB: if (jdbcObject != null) { try { value = read((Clob) jdbcObject); } catch (SQLException sqle) { value = ""; } catch (IOException ioe) { value = ""; } } break; case Types.ARRAY: try { ResultSet rs = ((Array) jdbcObject).getResultSet(); int arrayType = ((Array) jdbcObject).getBaseType(); boolean isNotNew = false; while (rs.next()) { String current = formatJDBCObject(rs.getObject(2), arrayType); if ("".equals(current.trim()) == false) { if (isNotNew) { value = value + ","; } else { isNotNew = !isNotNew; } value = value + current; } } if ("".equals(value) == false) { value = "{" + value + "}"; } } catch (SQLException sqle) { value = ""; } break; case Types.JAVA_OBJECT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); } break; case Types.DATE: if (jdbcObject != null) { value = formatter.formatDate(jdbcObject); } break; case Types.TIME: if (jdbcObject != null) { value = ((Time) jdbcObject).toString(); } break; case Types.TIMESTAMP: if (jdbcObject != null) { value = formatter.formatTimestamp(jdbcObject); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: if (jdbcObject != null) { value = jdbcObject.toString(); } else { value = "NULL"; } break; case Types.BINARY: value = new String((byte[]) jdbcObject); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.java
/** * Creates a new platform instance./*from ww w. j a va 2 s .c o m*/ */ public PostgreSqlPlatform() { PlatformInfo info = getPlatformInfo(); info.setPrimaryKeyColumnAutomaticallyRequired(true); // this is the default length though it might be changed when building PostgreSQL // in file src/include/postgres_ext.h info.setMaxIdentifierLength(31); info.addNativeTypeMapping(Types.ARRAY, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BINARY, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BIT, "BOOLEAN"); info.addNativeTypeMapping(Types.BLOB, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BOOLEAN, "BOOLEAN", Types.BIT); info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.DATALINK, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DECIMAL, "NUMERIC", Types.NUMERIC); info.addNativeTypeMapping(Types.DISTINCT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION"); info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE); info.addNativeTypeMapping(Types.JAVA_OBJECT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.LONGVARBINARY, "BYTEA"); info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.NULL, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.OTHER, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.REF, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.STRUCT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT); info.addNativeTypeMapping(Types.VARBINARY, "BYTEA", Types.LONGVARBINARY); info.setDefaultSize(Types.CHAR, 254); info.setDefaultSize(Types.VARCHAR, 254); // no support for specifying the size for these types (because they are mapped // to BYTEA which back-maps to BLOB) info.setHasSize(Types.BINARY, false); info.setHasSize(Types.VARBINARY, false); setSqlBuilder(new PostgreSqlBuilder(this)); setModelReader(new PostgreSqlModelReader(this)); }
From source file:org.apache.ddlutils.platform.DefaultValueHelper.java
/** * Converts a boolean default value to the given target type. * //w w w. j a va 2s. co m * @param defaultValue The default value * @param targetTypeCode The target type code * @return The converted value */ private Object convertBoolean(String defaultValue, int targetTypeCode) { Boolean value = null; Object result = null; try { value = (Boolean) ConvertUtils.convert(defaultValue, Boolean.class); } catch (ConversionException ex) { return defaultValue; } if ((targetTypeCode == Types.BIT) || (targetTypeCode == Types.BOOLEAN)) { result = value; } else if (TypeMap.isNumericType(targetTypeCode)) { result = (value.booleanValue() ? new Integer(1) : new Integer(0)); } else { result = value.toString(); } return result; }
From source file:com.tesora.dve.variables.BooleanValueConverter.java
@Override public ResultCollector getValueAsResult(Boolean in) throws PEException { return ResultCollectorFactory.getInstance(Types.BOOLEAN, in); }
From source file:net.sourceforge.vulcan.spring.jdbc.BuildInserter.java
public BuildInserter(DataSource dataSource) { setDataSource(dataSource);// w w w. jav a 2 s. c om setSql("insert into builds " + "(project_id, uuid, status, message_key," + "message_arg_0, message_arg_1, message_arg_2, message_arg_3, " + "build_reason_key, " + "build_reason_arg_0, build_reason_arg_1, build_reason_arg_2, build_reason_arg_3, " + "start_date, completion_date, build_number, update_type," + "work_dir, revision, revision_label, last_good_build_number," + "tag_name, repository_url, status_changed, scheduled_build," + "requested_by, revision_unavailable, broken_by_user_id, claimed_date, work_dir_vcs_clean) " + "values ((select id from project_names where name=?)," + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," + " (select id from users where username=?), ?, ?)"); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.TIMESTAMP)); declareParameter(new SqlParameter(Types.TIMESTAMP)); declareParameter(new SqlParameter(Types.NUMERIC)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.BIGINT)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.NUMERIC)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.BOOLEAN)); declareParameter(new SqlParameter(Types.BOOLEAN)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.BOOLEAN)); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.TIMESTAMP)); declareParameter(new SqlParameter(Types.BOOLEAN)); compile(); }
From source file:org.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query * into InputSplits./*from ww w .j a v a 2 s. co m*/ */ protected DBSplitter getSplitter(int sqlDataType) { switch (sqlDataType) { case Types.NUMERIC: case Types.DECIMAL: return new BigDecimalSplitter(); case Types.BIT: case Types.BOOLEAN: return new BooleanSplitter(); case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: return new IntegerSplitter(); case Types.REAL: case Types.FLOAT: case Types.DOUBLE: return new FloatSplitter(); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NVARCHAR: case Types.NCHAR: return new TextSplitter(); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return new DateSplitter(); default: // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT. return null; } }
From source file:org.apache.openjpa.jdbc.sql.H2Dictionary.java
@Override public int getPreferredType(int type) { if (type == Types.BIT) return Types.BOOLEAN; return type;//from w ww . j a v a 2s .c om }
From source file:org.schedoscope.export.jdbc.outputformat.JdbcOutputWritable.java
@Override public void write(PreparedStatement ps) throws SQLException { List<Pair<String, String>> record = fromArrayWritable(value); try {// ww w . j ava 2s .co m for (int i = 0; i < record.size(); i++) { String type = record.get(i).getLeft().toLowerCase(Locale.getDefault()); if (type.equals(JdbcOutputWritable.STRING)) { if (!record.get(i).getRight().equals("NULL")) { ps.setString(i + 1, record.get(i).getRight()); } else { ps.setNull(i + 1, Types.VARCHAR); } } else if (type.equals(JdbcOutputWritable.DOUBLE)) { if (!record.get(i).getRight().equals("NULL")) { ps.setDouble(i + 1, Double.parseDouble(record.get(i).getRight())); } else { ps.setNull(i + 1, Types.DOUBLE); } } else if (type.equals(JdbcOutputWritable.BOOLEAN)) { if (!record.get(i).getRight().equals("NULL")) { ps.setBoolean(i + 1, Boolean.parseBoolean(record.get(i).getRight())); } else { ps.setNull(i + 1, Types.BOOLEAN); } } else if (type.equals(JdbcOutputWritable.INTEGER)) { if (!record.get(i).getRight().equals("NULL")) { ps.setInt(i + 1, Integer.parseInt(record.get(i).getRight())); } else { ps.setNull(i + 1, Types.INTEGER); } } else if (type.equals(JdbcOutputWritable.LONG)) { if (!record.get(i).getRight().equals("NULL")) { ps.setLong(i + 1, Long.parseLong(record.get(i).getRight())); } else { ps.setNull(i + 1, Types.BIGINT); } } else { LOG.warn("Unknown column type: " + record.get(i).getLeft().toLowerCase(Locale.getDefault())); ps.setString(i + 1, record.get(i).getRight()); } } } catch (NumberFormatException n) { n.printStackTrace(); } }