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:com.haulmont.cuba.core.sys.persistence.EclipseLinkSessionEventListener.java
private void setDatabaseFieldParameters(Session session, DatabaseField field) { if (session.getPlatform() instanceof PostgreSQLPlatform) { field.setSqlType(Types.OTHER); field.setType(UUID.class); } else {/*from w ww. ja va 2 s. co m*/ field.setSqlType(Types.VARCHAR); field.setType(String.class); } field.setColumnDefinition("UUID"); }
From source file:Main.java
private static Vector getDataTypes(Connection con) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;/*from ww w. j av a 2s. c o m*/ else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } return dataTypes; }
From source file:org.xsystem.sql2.dml.DmlCommand.java
void setParms(CallableStatement cs, List<DmlParams> paramsSpec, Map<String, Object> values) throws SQLException { int i = 0;/*from w w w .ja v a2 s. c om*/ Connection con = cs.getConnection(); AbstactNativeHelper nativeHelper = nativeHelperFactory(con); for (DmlParams row : paramsSpec) { String paramName = row.getName(); Integer jdbcType = row.getJdbcType(); String objectType = row.getObjectType(); Object value = values.get(paramName); boolean in = row.isIn(); boolean out = row.isOut(); i = i + 1; if (in) { if (namedParams) { if (jdbcType == Types.OTHER) { cs.setObject(paramName, value); } else { value = setValue(value, jdbcType, objectType, con, nativeHelper); if (value != null) { value = convert(value, jdbcType); cs.setObject(paramName, value, jdbcType); } else { cs.setNull(paramName, jdbcType); } } } else { if (jdbcType == Types.OTHER) { cs.setObject(i, value); } else { if (jdbcType == JdbcTypeMapping.json) { nativeHelper.setJSONPARAM(cs, i, value); } else { value = setValue(value, jdbcType, objectType, con, nativeHelper); if (value != null) { value = convert(value, jdbcType); cs.setObject(i, value, jdbcType); } else { cs.setNull(i, jdbcType); } } } } } if (out) { if (namedParams) { if (jdbcType == Types.ARRAY || jdbcType == Types.STRUCT) { cs.registerOutParameter(paramName, jdbcType, objectType); } else { cs.registerOutParameter(paramName, jdbcType); } } else { if (jdbcType == Types.ARRAY || jdbcType == Types.STRUCT) { cs.registerOutParameter(i, jdbcType, objectType); } else { cs.registerOutParameter(i, jdbcType); } } } } }
From source file:hermes.store.schema.DefaultJDBCAdapter.java
private PreparedStatement createPreparedStatement(Connection connection, String sql, Object[] params) throws SQLException { final PreparedStatement stmt = connection.prepareStatement(sql); if (params != null) { for (int i = 0; i < params.length; i++) { if (params[i] != null) { stmt.setObject(i + 1, params[i]); } else { stmt.setNull(i + 1, Types.OTHER); }// w ww . j av a 2s . c o m } } return stmt; }
From source file:CreateNewType.java
private static Vector getDataTypes(Connection con, String typeToCreate) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;/*from w w w . j ava 2 s .c o m*/ else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } if (typeToCreate.equals("s")) { int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } } return dataTypes; }
From source file:com.micromux.cassandra.jdbc.CollectionsTest.java
@Test public void testUpdateList() throws Exception { if (LOG.isDebugEnabled()) LOG.debug("Test: 'testUpdateList'\n"); Statement statement = con.createStatement(); String update1 = "UPDATE testcollection SET L = L + [2,4,6] WHERE k = 1;"; statement.executeUpdate(update1);/*from w w w.j a va2 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("l"); List<Long> myList = (List<Long>) myObj; assertEquals(6, myList.size()); assertTrue(12345L == myList.get(2)); if (LOG.isDebugEnabled()) LOG.debug("l = '{}'", myObj); String update2 = "UPDATE testcollection SET L = [98,99,100] + L WHERE k = 1;"; statement.executeUpdate(update2); result = statement.executeQuery("SELECT * FROM testcollection WHERE k = 1;"); result.next(); myObj = result.getObject("l"); myList = (List<Long>) myObj; // 98, 99, 100, 1, 3, 12345, 2, 4, 6 // remove all of these values from the list - it should be empty assertEquals("Checking the size of the List", 9, myList.size()); myList.remove(Long.valueOf(98)); myList.remove(Long.valueOf(99)); myList.remove(Long.valueOf(100)); myList.remove(Long.valueOf(1)); myList.remove(Long.valueOf(3)); myList.remove(Long.valueOf(12345)); myList.remove(Long.valueOf(2)); myList.remove(Long.valueOf(4)); myList.remove(Long.valueOf(6)); assertEquals("List should now be empty", 0, myList.size()); if (LOG.isDebugEnabled()) LOG.debug("l = '{}'", myObj); String update3 = "UPDATE testcollection SET L[0] = 2000 WHERE k = 1;"; statement.executeUpdate(update3); result = statement.executeQuery("SELECT * FROM testcollection WHERE k = 1;"); result.next(); myObj = result.getObject("l"); myList = (List<Long>) myObj; if (LOG.isDebugEnabled()) LOG.debug("l = '{}'", myObj); // String update4 = "UPDATE testcollection SET L = L + ? WHERE k = 1;"; String update4 = "UPDATE testcollection SET L = ? WHERE k = 1;"; PreparedStatement prepared = con.prepareStatement(update4); List<Long> myNewList = new ArrayList<Long>(); myNewList.add(8888L); myNewList.add(9999L); prepared.setObject(1, myNewList, Types.OTHER); prepared.execute(); result = prepared.executeQuery("SELECT * FROM testcollection WHERE k = 1;"); result.next(); myObj = result.getObject("l"); myList = (List<Long>) myObj; if (LOG.isDebugEnabled()) LOG.debug("l (prepared)= '{}'\n", myObj); }
From source file:org.apache.nifi.processors.standard.util.TestJdbcCommon.java
@Test public void testCreateSchemaTypes() throws SQLException, IllegalArgumentException, IllegalAccessException { final Set<Integer> fieldsToIgnore = new HashSet<>(); fieldsToIgnore.add(Types.NULL); fieldsToIgnore.add(Types.OTHER); final Field[] fieldTypes = Types.class.getFields(); for (final Field field : fieldTypes) { final Object fieldObject = field.get(null); final int type = (int) fieldObject; if (fieldsToIgnore.contains(Types.NULL)) { continue; }//from www .j a v a 2 s . c o m final ResultSetMetaData metadata = mock(ResultSetMetaData.class); when(metadata.getColumnCount()).thenReturn(1); when(metadata.getColumnType(1)).thenReturn(type); when(metadata.getColumnName(1)).thenReturn(field.getName()); when(metadata.getTableName(1)).thenReturn("table"); final ResultSet rs = mock(ResultSet.class); when(rs.getMetaData()).thenReturn(metadata); try { JdbcCommon.createSchema(rs); } catch (final IllegalArgumentException | SQLException sqle) { sqle.printStackTrace(); Assert.fail("Failed when using type " + field.getName()); } } }
From source file:org.jumpmind.db.platform.AbstractJdbcDdlReader.java
protected 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)); result.add(new MetaDataColumnDescriptor("COLUMN_DEFAULT", 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("IS_AUTOINCREMENT", Types.VARCHAR, "YES")); result.add(new MetaDataColumnDescriptor("REMARKS", Types.VARCHAR)); return result; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type.spec) { case STRING:/*from w w w . j a v a 2 s .c om*/ if (type.isUnconstrained()) { return jdbcInfo("varchar", Types.VARCHAR); } else if (type.isClob()) { return jdbcInfo("text", Types.CLOB); } else { return jdbcInfo("varchar(%d)", type.length, Types.VARCHAR); } case ARRAY_STRING: if (type.isUnconstrained()) { return jdbcInfo("varchar[]", Types.ARRAY, "varchar", Types.VARCHAR); } else if (type.isClob()) { return jdbcInfo("text[]", Types.ARRAY, "text", Types.CLOB); } else { return jdbcInfo("varchar(%d)[]", type.length, Types.ARRAY, "varchar", Types.VARCHAR); } case BOOLEAN: return jdbcInfo("bool", Types.BIT); case ARRAY_BOOLEAN: return jdbcInfo("bool[]", Types.ARRAY, "bool", Types.BOOLEAN); case LONG: return jdbcInfo("int8", Types.BIGINT); case ARRAY_LONG: return jdbcInfo("int8[]", Types.ARRAY, "int8", Types.BIGINT); case DOUBLE: return jdbcInfo("float8", Types.DOUBLE); case ARRAY_DOUBLE: return jdbcInfo("float8[]", Types.ARRAY, "float8", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("timestamp", Types.TIMESTAMP); case ARRAY_TIMESTAMP: return jdbcInfo("timestamp[]", Types.ARRAY, "timestamp", Types.TIMESTAMP); case BLOBID: return jdbcInfo("varchar(40)", Types.VARCHAR); case ARRAY_BLOBID: return jdbcInfo("varchar(40)[]", Types.ARRAY, "varchar", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEIDPK: case NODEVAL: switch (idType) { case VARCHAR: return jdbcInfo("varchar(36)", Types.VARCHAR); case UUID: return jdbcInfo("uuid", Types.OTHER); case SEQUENCE: return jdbcInfo("int8", Types.BIGINT); } case NODEARRAY: switch (idType) { case VARCHAR: return jdbcInfo("varchar(36)[]", Types.ARRAY, "varchar", Types.VARCHAR); case UUID: return jdbcInfo("uuid[]", Types.ARRAY, "uuid", Types.OTHER); case SEQUENCE: return jdbcInfo("int8[]", Types.ARRAY, "int8", Types.BIGINT); } case SYSNAME: return jdbcInfo("varchar(250)", Types.VARCHAR); case SYSNAMEARRAY: return jdbcInfo("varchar(250)[]", Types.ARRAY, "varchar", Types.VARCHAR); case TINYINT: return jdbcInfo("int2", Types.SMALLINT); case INTEGER: return jdbcInfo("int4", Types.INTEGER); case ARRAY_INTEGER: return jdbcInfo("int4[]", Types.ARRAY, "int4", Types.INTEGER); case AUTOINC: return jdbcInfo("serial", Types.INTEGER); case FTINDEXED: if (compatibilityFulltextTable) { return jdbcInfo("tsvector", Types.OTHER); } else { return jdbcInfo("text", Types.CLOB); } case FTSTORED: if (compatibilityFulltextTable) { return jdbcInfo("tsvector", Types.OTHER); } else { return jdbcInfo("text", Types.CLOB); } case CLUSTERNODE: return jdbcInfo("int4", Types.INTEGER); case CLUSTERFRAGS: return jdbcInfo("varchar[]", Types.ARRAY, "varchar", Types.VARCHAR); } throw new AssertionError(type); }
From source file:org.springframework.jdbc.core.StatementCreatorUtils.java
/** * Set the specified PreparedStatement parameter to null, * respecting database-specific peculiarities. *//*w w w .ja v a 2s .co m*/ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, @Nullable String typeName) throws SQLException { if (sqlType == SqlTypeValue.TYPE_UNKNOWN || sqlType == Types.OTHER) { boolean useSetObject = false; Integer sqlTypeToUse = null; if (!shouldIgnoreGetParameterType) { try { sqlTypeToUse = ps.getParameterMetaData().getParameterType(paramIndex); } catch (SQLException ex) { if (logger.isDebugEnabled()) { logger.debug("JDBC getParameterType call failed - using fallback method instead: " + ex); } } } if (sqlTypeToUse == null) { // Proceed with database-specific checks sqlTypeToUse = Types.NULL; DatabaseMetaData dbmd = ps.getConnection().getMetaData(); String jdbcDriverName = dbmd.getDriverName(); String databaseProductName = dbmd.getDatabaseProductName(); if (databaseProductName.startsWith("Informix") || (jdbcDriverName.startsWith("Microsoft") && jdbcDriverName.contains("SQL Server"))) { // "Microsoft SQL Server JDBC Driver 3.0" versus "Microsoft JDBC Driver 4.0 for SQL Server" useSetObject = true; } else if (databaseProductName.startsWith("DB2") || jdbcDriverName.startsWith("jConnect") || jdbcDriverName.startsWith("SQLServer") || jdbcDriverName.startsWith("Apache Derby")) { sqlTypeToUse = Types.VARCHAR; } } if (useSetObject) { ps.setObject(paramIndex, null); } else { ps.setNull(paramIndex, sqlTypeToUse); } } else if (typeName != null) { ps.setNull(paramIndex, sqlType, typeName); } else { ps.setNull(paramIndex, sqlType); } }