List of usage examples for java.sql Types OTHER
int OTHER
To view the source code for java.sql Types OTHER.
Click Source Link
getObject
and setObject
. From source file:org.seasar.dbflute.logic.replaceschema.loaddata.impl.DfAbsractDataWriter.java
protected boolean processNull(String tableName, String columnName, Object value, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap) throws SQLException { if (!isNullValue(value)) { return false; }/*from w w w . j a va 2s . c o m*/ Map<String, Integer> cacheMap = _nullTypeCacheMap.get(tableName); if (cacheMap == null) { cacheMap = StringKeyMap.createAsFlexibleOrdered(); _nullTypeCacheMap.put(tableName, cacheMap); } final Integer cachedType = cacheMap.get(columnName); if (cachedType != null) { // cache hit ps.setNull(bindCount, cachedType); // basically no exception return true; } final DfColumnMeta columnInfo = columnInfoMap.get(columnName); if (columnInfo != null) { // use mapped type at first final String mappedJdbcType = _columnHandler.getColumnJdbcType(columnInfo); final Integer mappedJdbcDefValue = TypeMap.getJdbcDefValueByJdbcType(mappedJdbcType); try { ps.setNull(bindCount, mappedJdbcDefValue); cacheMap.put(columnName, mappedJdbcDefValue); } catch (SQLException e) { // retry by plain type final int plainJdbcDefValue = columnInfo.getJdbcDefValue(); try { ps.setNull(bindCount, plainJdbcDefValue); cacheMap.put(columnName, plainJdbcDefValue); } catch (SQLException ignored) { final ExceptionMessageBuilder br = new ExceptionMessageBuilder(); br.addNotice("Failed to execute setNull(bindCount, jdbcDefValue)."); br.addItem("Column"); br.addElement(tableName + "." + columnName); br.addElement(columnInfo.toString()); br.addItem("Mapped JDBC Type"); br.addElement(mappedJdbcType); br.addItem("First JDBC Def-Value"); br.addElement(mappedJdbcDefValue); br.addItem("Retry JDBC Def-Value"); br.addElement(plainJdbcDefValue); br.addItem("Retry Message"); br.addElement(ignored.getMessage()); String msg = br.buildExceptionMessage(); throw new DfJDBCException(msg, e); } } } else { // basically no way Integer tryType = Types.VARCHAR; // as default try { ps.setNull(bindCount, tryType); cacheMap.put(columnName, tryType); } catch (SQLException e) { tryType = Types.NUMERIC; try { ps.setNull(bindCount, tryType); cacheMap.put(columnName, tryType); } catch (SQLException ignored) { tryType = Types.TIMESTAMP; try { ps.setNull(bindCount, tryType); cacheMap.put(columnName, tryType); } catch (SQLException iignored) { tryType = Types.OTHER; try { ps.setNull(bindCount, tryType); // last try cacheMap.put(columnName, tryType); } catch (SQLException iiignored) { throw e; } } } } } return true; }
From source file:com.intbit.dao.ScheduleSocialPostDAO.java
public static void updateScheduleSocialPostDetails(Integer userid, Integer Scheduleid, Integer entity_id, String schedule_title, Timestamp schedule_time, String schedule_desc, Map<String, Object> metadataMap) throws SQLException, ParseException { JSONObject json_metadata = new JSONObject(); PGobject pg_object = new PGobject(); String query_string = "Update tbl_scheduled_entity_list" + " SET schedule_title = ?, schedule_time = ?," + " schedule_desc = ?" + " Where id = ?"; try (Connection conn = connectionManager.getConnection()) { try (PreparedStatement prepared_statement = conn.prepareStatement(query_string)) { prepared_statement.setString(1, schedule_title); prepared_statement.setTimestamp(2, schedule_time); prepared_statement.setString(3, schedule_desc); prepared_statement.setInt(4, Scheduleid); prepared_statement.executeUpdate(); }/* w w w. j av a 2 s . com*/ json_metadata = getjsonmetadata(entity_id, conn); query_string = "Update tbl_scheduled_socialpost_list" + " SET metadata = ?" + " Where id = ?"; pg_object.setType("json"); pg_object.setValue(AppConstants.GSON.toJson(metadataMap)); try (PreparedStatement prepared_statement = conn.prepareStatement(query_string)) { prepared_statement.setObject(1, pg_object, Types.OTHER); prepared_statement.setInt(2, entity_id); prepared_statement.executeUpdate(); } } }
From source file:org.apache.ddlutils.model.Database.java
/** * Initializes the model by establishing the relationships between elements in this model encoded * eg. in foreign keys etc. Also checks that the model elements are valid (table and columns have * a name, foreign keys rference existing tables etc.) *//* ww w . j av a 2 s. c o m*/ public void initialize() throws ModelException { // we have to setup // * target tables in foreign keys // * columns in foreign key references // * columns in indices // * columns in uniques HashSet namesOfProcessedTables = new HashSet(); HashSet namesOfProcessedColumns = new HashSet(); HashSet namesOfProcessedFks = new HashSet(); HashSet namesOfProcessedIndices = new HashSet(); int tableIdx = 0; if ((getName() == null) || (getName().length() == 0)) { throw new ModelException("The database model has no name"); } for (Iterator tableIt = _tables.iterator(); tableIt.hasNext(); tableIdx++) { Table curTable = (Table) tableIt.next(); if ((curTable.getName() == null) || (curTable.getName().length() == 0)) { throw new ModelException("The table nr. " + tableIdx + " has no name"); } if (namesOfProcessedTables.contains(curTable.getName())) { throw new ModelException("There are multiple tables with the name " + curTable.getName()); } namesOfProcessedTables.add(curTable.getName()); namesOfProcessedColumns.clear(); namesOfProcessedFks.clear(); namesOfProcessedIndices.clear(); for (int idx = 0; idx < curTable.getColumnCount(); idx++) { Column column = curTable.getColumn(idx); if ((column.getName() == null) || (column.getName().length() == 0)) { throw new ModelException( "The column nr. " + idx + " in table " + curTable.getName() + " has no name"); } if (namesOfProcessedColumns.contains(column.getName())) { throw new ModelException("There are multiple columns with the name " + column.getName() + " in the table " + curTable.getName()); } namesOfProcessedColumns.add(column.getName()); if ((column.getType() == null) || (column.getType().length() == 0)) { throw new ModelException( "The column nr. " + idx + " in table " + curTable.getName() + " has no type"); } if ((column.getTypeCode() == Types.OTHER) && !"OTHER".equalsIgnoreCase(column.getType())) { throw new ModelException("The column nr. " + idx + " in table " + curTable.getName() + " has an unknown type " + column.getType()); } namesOfProcessedColumns.add(column.getName()); } for (int idx = 0; idx < curTable.getForeignKeyCount(); idx++) { ForeignKey fk = curTable.getForeignKey(idx); String fkName = (fk.getName() == null ? "" : fk.getName()); String fkDesc = (fkName.length() == 0 ? "nr. " + idx : fkName); if (fkName.length() > 0) { if (namesOfProcessedFks.contains(fkName)) { throw new ModelException("There are multiple foreign keys in table " + curTable.getName() + " with the name " + fkName); } namesOfProcessedFks.add(fkName); } if (fk.getForeignTable() == null) { Table targetTable = findTable(fk.getForeignTableName(), true); if (targetTable == null) { final String msg = String.format( "The foreignkey [%s] in table [%s] references the undefined table [%s]. Will be ignored!", fkDesc, curTable.getName(), fk.getForeignTableName()); _log.debug(msg); continue; //throw new ModelException(msg); } else { fk.setForeignTable(targetTable); } } if (fk.getReferenceCount() == 0) { throw new ModelException("The foreignkey " + fkDesc + " in table " + curTable.getName() + " does not have any references"); } for (int refIdx = 0; refIdx < fk.getReferenceCount(); refIdx++) { Reference ref = fk.getReference(refIdx); if (ref.getLocalColumn() == null) { Column localColumn = curTable.findColumn(ref.getLocalColumnName(), true); if (localColumn == null) { throw new ModelException("The foreignkey " + fkDesc + " in table " + curTable.getName() + " references the undefined local column " + ref.getLocalColumnName()); } else { ref.setLocalColumn(localColumn); } } if (ref.getForeignColumn() == null) { Column foreignColumn = fk.getForeignTable().findColumn(ref.getForeignColumnName(), true); if (foreignColumn == null) { throw new ModelException("The foreignkey " + fkDesc + " in table " + curTable.getName() + " references the undefined local column " + ref.getForeignColumnName() + " in table " + fk.getForeignTable().getName()); } else { ref.setForeignColumn(foreignColumn); } } } } for (int idx = 0; idx < curTable.getIndexCount(); idx++) { Index index = curTable.getIndex(idx); String indexName = (index.getName() == null ? "" : index.getName()); String indexDesc = (indexName.length() == 0 ? "nr. " + idx : indexName); if (indexName.length() > 0) { if (namesOfProcessedIndices.contains(indexName)) { throw new ModelException("There are multiple indices in table " + curTable.getName() + " with the name " + indexName); } namesOfProcessedIndices.add(indexName); } if (index.getColumnCount() == 0) { throw new ModelException("The index " + indexDesc + " in table " + curTable.getName() + " does not have any columns"); } for (int indexColumnIdx = 0; indexColumnIdx < index.getColumnCount(); indexColumnIdx++) { IndexColumn indexColumn = index.getColumn(indexColumnIdx); Column column = curTable.findColumn(indexColumn.getName(), true); if (column == null) { throw new ModelException("The index " + indexDesc + " in table " + curTable.getName() + " references the undefined column " + indexColumn.getName()); } else { indexColumn.setColumn(column); } } } } }
From source file:org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory.java
protected TableModel parametrizeAndQuery(final DataRow parameters, final String translatedQuery, final String[] preparedParameterNames) throws SQLException { final boolean callableStatementQuery = isCallableStatementQuery(translatedQuery); final boolean callableStatementUsed = callableStatementQuery || isCallableStatement(translatedQuery); final Statement statement; if (preparedParameterNames.length == 0) { statement = getConnection(parameters).createStatement(getBestResultSetType(parameters), ResultSet.CONCUR_READ_ONLY); } else {/* w w w .j ava 2s . c o m*/ if (callableStatementUsed) { final CallableStatement pstmt = getConnection(parameters).prepareCall(translatedQuery, getBestResultSetType(parameters), ResultSet.CONCUR_READ_ONLY); if (isCallableStatementQuery(translatedQuery)) { pstmt.registerOutParameter(1, Types.OTHER); parametrize(parameters, preparedParameterNames, pstmt, false, 1); } else { parametrize(parameters, preparedParameterNames, pstmt, false, 0); } statement = pstmt; } else { final PreparedStatement pstmt = getConnection(parameters).prepareStatement(translatedQuery, getBestResultSetType(parameters), ResultSet.CONCUR_READ_ONLY); parametrize(parameters, preparedParameterNames, pstmt, isExpandArrays(), 0); statement = pstmt; } } final Object queryLimit = parameters.get(DataFactory.QUERY_LIMIT); try { if (queryLimit instanceof Number) { final Number i = (Number) queryLimit; final int max = i.intValue(); if (max > 0) { statement.setMaxRows(max); } } } catch (SQLException sqle) { // this fails for MySQL as their driver is buggy. We will not add workarounds here, as // all drivers are buggy and this is a race we cannot win. Put pressure on the driver // manufacturer instead. logger.warn("Driver indicated error: Failed to set query-limit: " + queryLimit, sqle); } final Object queryTimeout = parameters.get(DataFactory.QUERY_TIMEOUT); try { if (queryTimeout instanceof Number) { final Number i = (Number) queryTimeout; final int seconds = i.intValue(); if (seconds > 0) { statement.setQueryTimeout(seconds); } } } catch (SQLException sqle) { logger.warn("Driver indicated error: Failed to set query-timeout: " + queryTimeout, sqle); } // Track the currently running statement - just in case someone needs to cancel it final ResultSet res; try { currentRunningStatement = statement; if (preparedParameterNames.length == 0) { res = statement.executeQuery(translatedQuery); } else { final PreparedStatement pstmt = (PreparedStatement) statement; res = pstmt.executeQuery(); } } finally { currentRunningStatement = null; } // equalsIgnore, as this is what the ResultSetTableModelFactory uses. final boolean simpleMode = "simple".equalsIgnoreCase(getConfiguration().getConfigProperty( //$NON-NLS-1$ ResultSetTableModelFactory.RESULTSET_FACTORY_MODE)); //$NON-NLS-1$ if (simpleMode) { return ResultSetTableModelFactory.getInstance().generateDefaultTableModel(res, columnNameMapping); } return ResultSetTableModelFactory.getInstance().createTableModel(res, columnNameMapping, true); }
From source file:com.micromux.cassandra.jdbc.CollectionsTest.java
@Test public void testUpdateSet() throws Exception { if (LOG.isDebugEnabled()) LOG.debug("Test: 'testUpdateSet'\n"); Statement statement = con.createStatement(); // add some items to the set String update1 = "UPDATE testcollection SET S = S + {'green', 'white', 'orange'} WHERE k = 1;"; statement.executeUpdate(update1);/* ww w. j a v a 2 s .c o m*/ ResultSet result = statement.executeQuery("SELECT * FROM testcollection WHERE k = 1;"); result.next(); assertEquals(1, result.getInt("k")); Object myObj = result.getObject("s"); Set<String> mySet = (Set<String>) myObj; assertEquals(5, mySet.size()); assertTrue(mySet.contains("white")); if (LOG.isDebugEnabled()) LOG.debug("s = '{}'", myObj); // remove an item from the set String update2 = "UPDATE testcollection SET S = S - {'red'} WHERE k = 1;"; statement.executeUpdate(update2); result = statement.executeQuery("SELECT * FROM testcollection WHERE k = 1;"); result.next(); assertEquals(1, result.getInt("k")); myObj = result.getObject("s"); mySet = (Set<String>) myObj; assertEquals(4, mySet.size()); assertTrue(mySet.contains("white")); assertFalse(mySet.contains("red")); if (LOG.isDebugEnabled()) LOG.debug("s = '{}'", myObj); String update4 = "UPDATE testcollection SET S = ? WHERE k = 1;"; PreparedStatement prepared = con.prepareStatement(update4); Set<String> myNewSet = new HashSet<String>(); myNewSet.add("black"); myNewSet.add("blue"); prepared.setObject(1, myNewSet, Types.OTHER); prepared.execute(); result = prepared.executeQuery("SELECT * FROM testcollection WHERE k = 1;"); result.next(); myObj = result.getObject("s"); mySet = (Set<String>) myObj; if (LOG.isDebugEnabled()) LOG.debug("s (prepared)= '{}'\n", myObj); }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java
@Override public boolean isAllowedConversion(int expected, int actual, String actualName, int actualSize) { // CLOB vs VARCHAR compatibility if (expected == Types.VARCHAR && actual == Types.CLOB) { return true; }/*from w w w.ja va 2 s . com*/ if (expected == Types.CLOB && actual == Types.VARCHAR) { return true; } // INTEGER vs BIGINT compatibility if (expected == Types.BIGINT && actual == Types.INTEGER) { return true; } if (expected == Types.INTEGER && actual == Types.BIGINT) { return true; } // TSVECTOR vs CLOB compatibility during upgrade tests // where column detection is done before upgrade test setup if (expected == Types.CLOB && (actual == Types.OTHER && actualName.equals("tsvector"))) { return true; } return false; }
From source file:org.jumpmind.db.model.Database.java
/** * Initializes the model by establishing the relationships between elements * in this model encoded eg. in foreign keys etc. Also checks that the model * elements are valid (table and columns have a name, foreign keys rference * existing tables etc.)/* ww w .j av a 2s . c om*/ */ public void initialize() throws ModelException { // we have to setup // * target tables in foreign keys // * columns in foreign key references // * columns in indices // * columns in uniques HashSet<String> namesOfProcessedTables = new HashSet<String>(); HashSet<String> namesOfProcessedColumns = new HashSet<String>(); HashSet<String> namesOfProcessedFks = new HashSet<String>(); HashSet<String> namesOfProcessedIndices = new HashSet<String>(); int tableIdx = 0; for (Iterator<Table> tableIt = tables.iterator(); tableIt.hasNext(); tableIdx++) { Table curTable = tableIt.next(); if ((curTable.getName() == null) || (curTable.getName().length() == 0)) { throw new ModelException("The table nr. " + tableIdx + " has no name"); } if (namesOfProcessedTables.contains(curTable.getFullyQualifiedTableName())) { throw new ModelException("There are multiple tables with the name " + curTable.getName()); } namesOfProcessedTables.add(curTable.getFullyQualifiedTableName()); namesOfProcessedColumns.clear(); namesOfProcessedFks.clear(); namesOfProcessedIndices.clear(); for (int idx = 0; idx < curTable.getColumnCount(); idx++) { Column column = curTable.getColumn(idx); if ((column.getName() == null) || (column.getName().length() == 0)) { throw new ModelException( "The column nr. " + idx + " in table " + curTable.getName() + " has no name"); } if (namesOfProcessedColumns.contains(column.getName())) { throw new ModelException("There are multiple column with the name " + column.getName() + " in the table " + curTable.getName()); } namesOfProcessedColumns.add(column.getName()); if ((column.getMappedType() == null) || (column.getMappedType().length() == 0)) { throw new ModelException( "The column nr. " + idx + " in table " + curTable.getName() + " has no type"); } if ((column.getMappedTypeCode() == Types.OTHER) && !"OTHER".equalsIgnoreCase(column.getMappedType())) { throw new ModelException("The column nr. " + idx + " in table " + curTable.getName() + " has an unknown type " + column.getMappedType()); } namesOfProcessedColumns.add(column.getName()); } for (int idx = 0; idx < curTable.getForeignKeyCount(); idx++) { ForeignKey fk = curTable.getForeignKey(idx); String fkName = (fk.getName() == null ? "" : fk.getName()); String fkDesc = (fkName.length() == 0 ? "nr. " + idx : fkName); if (fkName.length() > 0) { if (namesOfProcessedFks.contains(fkName)) { throw new ModelException("There are multiple foreign keys in table " + curTable.getName() + " with the name " + fkName); } namesOfProcessedFks.add(fkName); } if (fk.getForeignTable() == null) { Table targetTable = findTable(fk.getForeignTableName(), true); if (targetTable != null) { fk.setForeignTable(targetTable); } else { log.debug("The foreignkey " + fkDesc + " in table " + curTable.getName() + " references the undefined table " + fk.getForeignTableName() + ". This could be because the foreign key table was in another schema which is a bug that should be fixed in the future."); } } if (fk.getForeignTable() != null) { for (int refIdx = 0; refIdx < fk.getReferenceCount(); refIdx++) { Reference ref = fk.getReference(refIdx); if (ref.getLocalColumn() == null) { Column localColumn = curTable.findColumn(ref.getLocalColumnName(), true); if (localColumn == null) { throw new ModelException("The foreignkey " + fkDesc + " in table " + curTable.getName() + " references the undefined local column " + ref.getLocalColumnName()); } else { ref.setLocalColumn(localColumn); } } if (ref.getForeignColumn() == null) { Column foreignColumn = fk.getForeignTable().findColumn(ref.getForeignColumnName(), true); if (foreignColumn == null) { throw new ModelException("The foreignkey " + fkDesc + " in table " + curTable.getName() + " references the undefined local column " + ref.getForeignColumnName() + " in table " + fk.getForeignTable().getName()); } else { ref.setForeignColumn(foreignColumn); } } } } } for (int idx = 0; idx < curTable.getIndexCount(); idx++) { IIndex index = curTable.getIndex(idx); String indexName = (index.getName() == null ? "" : index.getName()); if (indexName.length() > 0) { if (namesOfProcessedIndices.contains(indexName)) { throw new ModelException("There are multiple indices in table " + curTable.getName() + " with the name " + indexName); } namesOfProcessedIndices.add(indexName); } for (int indexColumnIdx = 0; indexColumnIdx < index.getColumnCount(); indexColumnIdx++) { IndexColumn indexColumn = index.getColumn(indexColumnIdx); Column column = curTable.findColumn(indexColumn.getName(), true); indexColumn.setColumn(column); } } } }
From source file:com.squid.core.domain.operators.ExtendedType.java
private String getTypeName(int SQLType) { switch (SQLType) { case Types.ARRAY: return "ARRAY"; case Types.BIGINT: return "INTEGER"; case Types.BINARY: return "BINARY"; case Types.BIT: return "BIT"; case Types.BLOB: return "BLOB"; case Types.BOOLEAN: return "BOOLEAN"; case Types.CHAR: return "CHAR"; case Types.CLOB: return "CLOB"; case Types.DATALINK: return "DATALINK"; case Types.DATE: return "DATE"; case Types.DECIMAL: return "DECIMAL"; case Types.DOUBLE: return "DOUBLE"; case Types.FLOAT: return "FLOAT"; case Types.INTEGER: return "INTEGER"; case Types.JAVA_OBJECT: return "JAVA_OBJECT"; case Types.LONGNVARCHAR: return "LONGNVARCHAR"; case Types.LONGVARBINARY: return "LONGVARBINARY"; case Types.NCHAR: return "NCHAR"; case Types.NCLOB: return "NCLOB"; case Types.NULL: return "UNDEFINED";// case Types.NUMERIC: return "NUMERIC"; case Types.NVARCHAR: return "NVARCHAR"; case Types.OTHER: return "UNDEFINED";// case Types.REAL: return "REAL"; case Types.REF: return "REF"; case Types.ROWID: return "ROWID"; case Types.SMALLINT: return "SMALLINT"; case Types.SQLXML: return "SQLXML"; case Types.STRUCT: return "STRUCT"; case Types.TIME: return "TIME"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.TINYINT: return "TINYINT"; case Types.VARBINARY: return "VARBINARY"; case Types.VARCHAR: return "VARCHAR"; default:// w w w.ja v a 2s .c om return "UNDEFINED";// } }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java
@Override public void setId(PreparedStatement ps, int index, Serializable value) throws SQLException { switch (idType) { case VARCHAR: ps.setObject(index, value);// ww w .j ava2s .c om break; case UUID: ps.setObject(index, value, Types.OTHER); break; case SEQUENCE: setIdLong(ps, index, value); break; default: throw new AssertionError(); } }
From source file:com.alibaba.otter.shared.common.utils.meta.DdlUtils.java
private static List<MetaDataColumnDescriptor> initColumnsForColumn() { List<MetaDataColumnDescriptor> result = new ArrayList<MetaDataColumnDescriptor>(); // As suggested by Alexandre Borgoltz, we're reading the COLUMN_DEF // first because Oracle // has problems otherwise (it seemingly requires a LONG column to be the // first to be read) // See also DDLUTILS-29 result.add(new MetaDataColumnDescriptor("COLUMN_DEF", Types.VARCHAR)); // we're also reading the table name so that a model reader impl can // filter manually result.add(new MetaDataColumnDescriptor("TABLE_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("COLUMN_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("TYPE_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("DATA_TYPE", Types.INTEGER, new Integer(java.sql.Types.OTHER))); result.add(new MetaDataColumnDescriptor("NUM_PREC_RADIX", Types.INTEGER, new Integer(10))); result.add(new MetaDataColumnDescriptor("DECIMAL_DIGITS", Types.INTEGER, new Integer(0))); result.add(new MetaDataColumnDescriptor("COLUMN_SIZE", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("IS_NULLABLE", Types.VARCHAR, "YES")); result.add(new MetaDataColumnDescriptor("REMARKS", Types.VARCHAR)); return result; }