List of usage examples for java.sql CallableStatement getTimestamp
java.sql.Timestamp getTimestamp(String parameterName) throws SQLException;
TIMESTAMP
parameter as a java.sql.Timestamp
object. From source file:org.apache.lucene.store.jdbc.JdbcDirectory.java
/** * Delets all the file entries that are marked to be deleted, and they were marked * "delta" time ago (base on database time, if possible by dialect). */// w w w . j a va2 s. co m public void deleteMarkDeleted(long delta) throws IOException { long currentTime = System.currentTimeMillis(); if (dialect.supportsCurrentTimestampSelection()) { String timestampSelectString = dialect.getCurrentTimestampSelectString(); if (dialect.isCurrentTimestampSelectStringCallable()) { currentTime = ((Long) jdbcTemplate.executeCallable(timestampSelectString, new JdbcTemplate.CallableStatementCallback() { public void fillCallableStatement(CallableStatement cs) throws Exception { cs.registerOutParameter(1, java.sql.Types.TIMESTAMP); } public Object readCallableData(CallableStatement cs) throws Exception { Timestamp timestamp = cs.getTimestamp(1); return new Long(timestamp.getTime()); } })).longValue(); } else { currentTime = ((Long) jdbcTemplate.executeSelect(timestampSelectString, new JdbcTemplate.ExecuteSelectCallback() { public void fillPrepareStatement(PreparedStatement ps) throws Exception { // nothing to do here } public Object execute(ResultSet rs) throws Exception { rs.next(); Timestamp timestamp = rs.getTimestamp(1); return new Long(timestamp.getTime()); } })).longValue(); } } final long deleteBefore = currentTime - delta; jdbcTemplate.executeUpdate(table.sqlDeletaMarkDeleteByDelta(), new JdbcTemplate.PrepateStatementAwareCallback() { public void fillPrepareStatement(PreparedStatement ps) throws Exception { ps.setBoolean(1, true); ps.setTimestamp(2, new Timestamp(deleteBefore)); } }); }
From source file:com.netspective.axiom.sql.StoredProcedureParameter.java
/** * Extract the OUT parameter values from the callable statment and * assign them to the value of the parameter. *///from w w w . j av a2 s. c om public void extract(ConnectionContext cc, CallableStatement stmt) throws SQLException { if (getType().getValueIndex() == StoredProcedureParameter.Type.IN) return; int index = this.getIndex(); QueryParameterType paramType = getSqlType(); int jdbcType = paramType.getJdbcType(); String identifier = paramType.getIdentifier(); // result sets are special if (identifier.equals(QueryParameterType.RESULTSET_IDENTIFIER)) { ResultSet rs = (ResultSet) stmt.getObject(index); QueryResultSet qrs = new QueryResultSet(getParent().getProcedure(), cc, rs); value.getValue(cc).setValue(qrs); return; } switch (jdbcType) { case Types.VARCHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; case Types.INTEGER: value.getValue(cc).setValue(new Integer(stmt.getInt(index))); break; case Types.DOUBLE: value.getValue(cc).setValue(new Double(stmt.getDouble(index))); break; case Types.CLOB: Clob clob = stmt.getClob(index); value.getValue(cc).setTextValue(clob.getSubString(1, (int) clob.length())); break; case java.sql.Types.ARRAY: Array array = stmt.getArray(index); value.getValue(cc).setValue(array); break; case java.sql.Types.BIGINT: long bigint = stmt.getLong(index); value.getValue(cc).setValue(new Long(bigint)); break; case java.sql.Types.BINARY: value.getValue(cc).setTextValue(new String(stmt.getBytes(index))); break; case java.sql.Types.BIT: boolean bit = stmt.getBoolean(index); value.getValue(cc).setValue(new Boolean(bit)); case java.sql.Types.BLOB: value.getValue(cc).setValue(stmt.getBlob(index)); break; case java.sql.Types.CHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; case java.sql.Types.DATE: value.getValue(cc).setValue(stmt.getDate(index)); break; case java.sql.Types.DECIMAL: value.getValue(cc).setValue(stmt.getBigDecimal(index)); break; case java.sql.Types.DISTINCT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.FLOAT: value.getValue(cc).setValue(new Float(stmt.getFloat(index))); break; case java.sql.Types.JAVA_OBJECT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.LONGVARBINARY: value.getValue(cc).setTextValue(new String(stmt.getBytes(index))); break; case java.sql.Types.LONGVARCHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; //case java.sql.Types.NULL: // value.getValue(cc).setValue(null); // break; case java.sql.Types.NUMERIC: value.getValue(cc).setValue(stmt.getBigDecimal(index)); break; case java.sql.Types.OTHER: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.REAL: value.getValue(cc).setValue(new Float(stmt.getFloat(index))); break; //case java.sql.Types.REF: // Ref ref = stmt.getRef(index); // break; case java.sql.Types.SMALLINT: short sh = stmt.getShort(index); value.getValue(cc).setValue(new Short(sh)); break; case java.sql.Types.STRUCT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.TIME: value.getValue(cc).setValue(stmt.getTime(index)); break; case java.sql.Types.TIMESTAMP: value.getValue(cc).setValue(stmt.getTimestamp(index)); break; case java.sql.Types.TINYINT: byte b = stmt.getByte(index); value.getValue(cc).setValue(new Byte(b)); break; case java.sql.Types.VARBINARY: value.getValue(cc).setValue(stmt.getBytes(index)); break; default: throw new RuntimeException( "Unknown JDBC Type set for stored procedure parameter '" + this.getName() + "'."); } }
From source file:org.siphon.jssql.SqlExecutor.java
private Object translateOutputParameterValue(int sqlType, CallableStatement cs, int index) throws SQLException, SqlExecutorException, ScriptException { Object obj = cs.getObject(index); if (obj == null) { return null; } else {//from ww w .java 2 s . c om switch (sqlType) { case Types.DATE: obj = cs.getDate(index); case Types.TIME: obj = cs.getTime(index); case Types.TIMESTAMP: obj = cs.getTimestamp(index); } } Object result = jdbcReturnTypeToJsObject(obj); if (result instanceof String) { return ((String) result).trim(); } else { return result; } }
From source file:org.wso2.ws.dataservice.DBUtils.java
private static String setOutparameterValue(CallableStatement cs, Query query, String resultSetFieldName) throws SQLException, AxisFault { // This could be an out parameter //Procedure returns both result & out parameters String elementValue = ""; Param param = query.getParam(resultSetFieldName); if (param != null) { if ("OUT".equals(param.getType()) || "INOUT".equals(param.getType())) { if (param.getSqlType().equals(DBConstants.DataTypes.STRING)) { elementValue = cs.getString(param.getOrdinal()); } else if (param.getSqlType().equals(DBConstants.DataTypes.DOUBLE)) { elementValue = String.valueOf(cs.getDouble(param.getOrdinal())); } else if (param.getSqlType().equals(DBConstants.DataTypes.BIGINT)) { elementValue = String.valueOf(cs.getLong(param.getOrdinal())); } else if (param.getSqlType().equals(DBConstants.DataTypes.INTEGER)) { elementValue = String.valueOf(cs.getInt(param.getOrdinal())); } else if (param.getSqlType().equals(DBConstants.DataTypes.TIME)) { elementValue = String.valueOf(cs.getTime(param.getOrdinal())); } else if (param.getSqlType().equals(DBConstants.DataTypes.DATE)) { elementValue = String.valueOf(cs.getDate(param.getOrdinal())); } else if (param.getSqlType().equals(DBConstants.DataTypes.TIMESTAMP)) { elementValue = String.valueOf(cs.getTimestamp(param.getOrdinal())); } else { log.error("Unsupported data type : " + param.getSqlType()); throw new AxisFault("Unsupported data type : " + param.getSqlType()); }/*from w ww .ja v a 2s.com*/ } } return elementValue; }