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.jdbc.metadata.basic.DfProcedureExtractor.java
protected void setupProcedureColumnMetaInfo(DfProcedureMeta procedureMetaInfo, ResultSet columnRs) throws SQLException { final Set<String> uniqueSet = new HashSet<String>(); while (columnRs.next()) { // /- - - - - - - - - - - - - - - - - - - - - - - - // same policy as table process about JDBC handling // (see DfTableHandler.java) // - - - - - - - - - -/ final String columnName = columnRs.getString("COLUMN_NAME"); // filter duplicated informations // because Oracle package procedure may return them if (uniqueSet.contains(columnName)) { continue; }/*from w w w .j a v a 2 s . c om*/ uniqueSet.add(columnName); final Integer procedureColumnType; { final String columnType = columnRs.getString("COLUMN_TYPE"); final int unknowType = DatabaseMetaData.procedureColumnUnknown; if (Srl.is_NotNull_and_NotTrimmedEmpty(columnType)) { procedureColumnType = toInt("columnType", columnType); } else { procedureColumnType = unknowType; } } final int jdbcType; { int tmpJdbcType = Types.OTHER; String dataType = null; try { dataType = columnRs.getString("DATA_TYPE"); } catch (RuntimeException ignored) { // pinpoint patch // for example, SQLServer throws an exception // if the procedure is a function that returns table type final String procdureName = procedureMetaInfo.getProcedureFullQualifiedName(); log("*Failed to get data type: " + procdureName + "." + columnName); tmpJdbcType = Types.OTHER; } if (Srl.is_NotNull_and_NotTrimmedEmpty(dataType)) { tmpJdbcType = toInt("dataType", dataType); } jdbcType = tmpJdbcType; } final String dbTypeName = columnRs.getString("TYPE_NAME"); // uses getString() to get null value // (getInt() returns zero when a value is no defined) final Integer columnSize; { final String precision = columnRs.getString("PRECISION"); if (Srl.is_NotNull_and_NotTrimmedEmpty(precision)) { columnSize = toInt("precision", precision); } else { final String length = columnRs.getString("LENGTH"); if (Srl.is_NotNull_and_NotTrimmedEmpty(length)) { columnSize = toInt("length", length); } else { columnSize = null; } } } final Integer decimalDigits; { final String scale = columnRs.getString("SCALE"); if (Srl.is_NotNull_and_NotTrimmedEmpty(scale)) { decimalDigits = toInt("scale", scale); } else { decimalDigits = null; } } final String columnComment = columnRs.getString("REMARKS"); final DfProcedureColumnMeta procedureColumnMetaInfo = new DfProcedureColumnMeta(); procedureColumnMetaInfo.setColumnName(columnName); if (procedureColumnType == DatabaseMetaData.procedureColumnUnknown) { procedureColumnMetaInfo.setProcedureColumnType(DfProcedureColumnType.procedureColumnUnknown); } else if (procedureColumnType == DatabaseMetaData.procedureColumnIn) { procedureColumnMetaInfo.setProcedureColumnType(DfProcedureColumnType.procedureColumnIn); } else if (procedureColumnType == DatabaseMetaData.procedureColumnInOut) { procedureColumnMetaInfo.setProcedureColumnType(DfProcedureColumnType.procedureColumnInOut); } else if (procedureColumnType == DatabaseMetaData.procedureColumnOut) { procedureColumnMetaInfo.setProcedureColumnType(DfProcedureColumnType.procedureColumnOut); } else if (procedureColumnType == DatabaseMetaData.procedureColumnReturn) { procedureColumnMetaInfo.setProcedureColumnType(DfProcedureColumnType.procedureColumnReturn); } else if (procedureColumnType == DatabaseMetaData.procedureColumnResult) { procedureColumnMetaInfo.setProcedureColumnType(DfProcedureColumnType.procedureColumnResult); } else { throw new IllegalStateException("Unknown procedureColumnType: " + procedureColumnType); } procedureColumnMetaInfo.setJdbcDefType(jdbcType); procedureColumnMetaInfo.setDbTypeName(dbTypeName); procedureColumnMetaInfo.setColumnSize(columnSize); procedureColumnMetaInfo.setDecimalDigits(decimalDigits); procedureColumnMetaInfo.setColumnComment(columnComment); procedureMetaInfo.addProcedureColumn(procedureColumnMetaInfo); } adjustProcedureColumnList(procedureMetaInfo); }
From source file:org.apache.openjpa.jdbc.sql.PostgresDictionary.java
/** * If column is an XML column, PostgreSQL requires that its value is set * by using {@link PreparedStatement#setObject(int, Object, int)} * with {@link Types#OTHER} as the third argument. *///from ww w . ja va 2 s. co m public void setClobString(PreparedStatement stmnt, int idx, String val, Column col) throws SQLException { if (col != null && col.isXML()) stmnt.setObject(idx, val, Types.OTHER); else super.setClobString(stmnt, idx, val, col); }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper.java
protected void setToPreparedStatementIdArray(PreparedStatement ps, int index, Serializable idArray) throws SQLException { if (idArray instanceof String) { ps.setString(index, (String) idArray); } else {/*w w w . j a v a 2 s. co m*/ Array array = dialect.createArrayOf(Types.OTHER, (Object[]) idArray, connection); ps.setArray(index, array); } }
From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexer.java
private int[] getSQLTypes(Object[] varNames) { int[] result = new int[varNames.length]; Map<String, LiteralDef> map = this.getSettings().getIndexGraph().getLiteralDefMap(); for (int i = 0; i < varNames.length; i++) { LiteralDef literalDef = map.get(varNames[i]); if (literalDef == null) { result[i] = Types.VARCHAR; } else if (DataTypeURI.isGeometry(literalDef.getType())) { result[i] = Types.OTHER; } else if (DataTypeURI.DATETIME.equals(literalDef.getType())) { result[i] = Types.TIMESTAMP; }// ww w .j ava 2 s .co m } return result; }
From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexer.java
private Object getSQLValue(Value value, int type) { if (type == Types.OTHER) { return IndexedStatement.asGeometry((Literal) value, true); } else if (type == Types.TIMESTAMP) { try {//from w ww . j a v a 2s .co m return new java.sql.Timestamp(DateFormatter.getInstance().parse(value.stringValue()).getTime()); } catch (java.text.ParseException e) { e.printStackTrace(); } } else { return value.stringValue(); } return null; }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.JDBCConnector.java
public List<RowVO> getRows(String sql, List<ColumnVO> columns) throws Exception { List<RowVO> rows = new LinkedList<RowVO>(); Exception error = null;/*w w w . j a v a2 s. c o m*/ Connection connection = null; PreparedStatement preparedStmnt = null; try { DataSource dataSource = poolDataSources.get(schemaId); connection = dataSource.getConnection(); connection.setAutoCommit(false); preparedStmnt = connection.prepareStatement(sql); ResultSet result = preparedStmnt.executeQuery(); while (result.next()) { RowVO row = new RowVO(); for (ColumnVO column : columns) { String columnName = column.getNameOnTable(); String columnValue = null; Object columnValueObj = result.getObject(columnName); if (columnValueObj != null) { columnValue = columnValueObj.toString(); } /* if the column is a geometry type then set the * geometry column name of the row */ if (column.getSqlType() == Types.OTHER) { row.setGeomFieldName(columnName); } row.addField(columnName, columnValue); } rows.add(row); } } catch (SQLException e) { error = e; } finally { if (preparedStmnt != null) { try { preparedStmnt.close(); } catch (SQLException se2) { log.warn("No se pudo cerrar el statment: ".concat(se2.getLocalizedMessage())); } } if (connection != null) { try { if (error != null) { connection.rollback(); } } catch (SQLException se) { log.warn("Se produjo un error al manejar la conexin: ".concat(se.getLocalizedMessage())); } try { connection.close(); } catch (SQLException se) { log.warn("Se produjo un error al intentar cerrar la conexin: " .concat(se.getLocalizedMessage())); } } } if (error != null) { throw error; } return rows; }
From source file:org.enlacerh.util.FileUploadController.java
/** * Rutina que ejecuta el control de proceso de licencias de grupos de trabajadores. * Por ejemplo si la licencia es hasta 25 y el usuario carga mas de 25 el procedimiento * almacenado en la base de datos elimina los trabajadres de 25 en adelante **///from www. j a v a 2s . co m private void actAutoSrv(String cia, Integer anio, Integer mes, String user, String opcauto) throws NamingException { //Pool de conecciones JNDI(). Cambio de metodologa de conexin a bd. Julio 2010 Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); try { Connection con = ds.getConnection(); CallableStatement proc = null; proc = con.prepareCall("{? = CALL act_autosrv(?,?,?,?,?)}"); proc.registerOutParameter(1, Types.OTHER); proc.setString(2, cia); proc.setInt(3, anio); proc.setInt(4, mes); proc.setString(5, user); proc.setString(6, opcauto); proc.execute(); //System.out.println("Compaa: " + cia); //System.out.println("Ao: " + anio); //System.out.println("Mes: " + mes); //System.out.println("Usuario: " + user); //System.out.println("Opcin " + opcauto); // proc.close(); con.close(); //System.out.println("Actualizando"); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.acmsl.queryj.metadata.engines.JdbcTypeManager.java
/** * Retrieves the JDBC type for given class. * @param type the type to convert./* w w w.j ava 2s . co m*/ * @return the constant in {@link Types}. */ public int getJdbcType(@NotNull final Class<?> type) { final int result; if (INVERSE_CLASS_MAPPING.containsKey(type)) { result = INVERSE_CLASS_MAPPING.get(type); } else { result = Types.OTHER; } return result; }
From source file:org.apache.hive.jdbc.TestJdbcDriver2.java
@Test public void testIntervalTypes() throws Exception { Statement stmt = con.createStatement(); // Since interval types not currently supported as table columns, need to create them // as expressions. ResultSet res = stmt/*from ww w .j ava 2s . co m*/ .executeQuery("select case when c17 is null then null else interval '1' year end as col1," + " c17 - c17 as col2 from " + dataTypeTableName + " order by col1"); ResultSetMetaData meta = res.getMetaData(); assertEquals("col1", meta.getColumnLabel(1)); assertEquals(java.sql.Types.OTHER, meta.getColumnType(1)); assertEquals("interval_year_month", meta.getColumnTypeName(1)); assertEquals(11, meta.getColumnDisplaySize(1)); assertEquals(11, meta.getPrecision(1)); assertEquals(0, meta.getScale(1)); assertEquals(HiveIntervalYearMonth.class.getName(), meta.getColumnClassName(1)); assertEquals("col2", meta.getColumnLabel(2)); assertEquals(java.sql.Types.OTHER, meta.getColumnType(2)); assertEquals("interval_day_time", meta.getColumnTypeName(2)); assertEquals(29, meta.getColumnDisplaySize(2)); assertEquals(29, meta.getPrecision(2)); assertEquals(0, meta.getScale(2)); assertEquals(HiveIntervalDayTime.class.getName(), meta.getColumnClassName(2)); // row 1 - results should be null assertTrue(res.next()); // skip the last (partitioning) column since it is always non-null for (int i = 1; i < meta.getColumnCount(); i++) { assertNull("Column " + i + " should be null", res.getObject(i)); } // row 2 - results should be null assertTrue(res.next()); for (int i = 1; i < meta.getColumnCount(); i++) { assertNull("Column " + i + " should be null", res.getObject(i)); } // row 3 assertTrue(res.next()); assertEquals("1-0", res.getString(1)); assertEquals(1, ((HiveIntervalYearMonth) res.getObject(1)).getYears()); assertEquals("0 00:00:00.000000000", res.getString(2)); assertEquals(0, ((HiveIntervalDayTime) res.getObject(2)).getDays()); }
From source file:org.enlacerh.util.FileUploadController.java
/** * Rutina que ejecuta el control de proceso de licencias de grupos de trabajadores. * Por ejemplo si la licencia es hasta 25 y el usuario carga mas de 25 el procedimiento * almacenado en la base de datos elimina los trabajadres de 25 en adelante **//* ww w .jav a2 s .c o m*/ private void actCaracteres() throws NamingException { //Pool de conecciones JNDI(). Cambio de metodologa de conexin a bd. Julio 2010 Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); try { Connection con = ds.getConnection(); CallableStatement proc = null; proc = con.prepareCall("{? = CALL act_caracteres()}"); proc.registerOutParameter(1, Types.OTHER); proc.execute(); //System.out.println("Compaa: " + cia); //System.out.println("Ao: " + anio); //System.out.println("Mes: " + mes); //System.out.println("Usuario: " + user); //System.out.println("Opcin " + opcauto); // proc.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } }