List of usage examples for java.sql CallableStatement getObject
Object getObject(String parameterName) throws SQLException;
Object
in the Java programming language. From source file:com.intuit.it.billing.data.BillingDAOImpl.java
/** * getCustomerInfo/* ww w. j a v a 2 s .co m*/ * <p/> * <p/> * <b>DATABASE PROCEDURE:</b> * * @code * FUNCTION fn_get_customer * ( * customer IN VARCHAR2, * bill_item_no IN VARCHAR2, * order_no IN VARCHAR2, * pson IN VARCHAR2 * ) * RETURN ref_cursor; * @endcode * <p/> * <b>DATABASE RESULT SET:</b> * <ul> * <li>ACCOUNT_NO,</li> * <li>FIRST_NAME,</li> * <li>LAST_NAME,</li> * <li>COMPANY,</li> * <li>PHONE,</li> * <li>ADDRESS,</li> * <li>CITY,</li> * <li>STATE,</li> * <li>ZIP,</li> * <li>COUNTRY </li> * </ul> * * @param customer - The Customer.accountNo of the customer we want to find * @param billNo - A bill number (e.g. B1-1111) OR bill line item number (e.g. B1-111,5) of the customer we want to find - remove everything after the comma * @param orderNo - An order number (e.g. 200000011111) OR order line item number (e.g. 200000011111,5) of the customer we want to find - remove everything after the comma * @param pson - A BRM trans_id number (Paymenttech merchant number) of the payment event * * @return A Customer object * */ @Override public Customer getCustomerInfo(String customer, String billNo, String orderNo, String pson) throws JSONException { Customer c = null; String query = "begin ? := billing_inquiry.fn_get_customer( ?, ?, ?, ? ); end;"; Connection conn = null; ResultSet rs = null; // DB Connection try { conn = this.getConnection(); } catch (SQLException e) { throw JSONException.sqlError(e); } catch (NamingException e) { throw JSONException.namingError(e.toString()); } try { CallableStatement stmt = conn.prepareCall(query); stmt.registerOutParameter(1, OracleTypes.CURSOR); stmt.setString(2, customer); stmt.setString(3, billNo); stmt.setString(4, orderNo); stmt.setString(5, pson); stmt.execute(); rs = (ResultSet) stmt.getObject(1); while (rs.next()) { c = new Customer(); c.setAccountNo(rs.getString("ACCOUNT_NO")); c.setFirstName(rs.getString("FIRST_NAME")); c.setLastName(rs.getString("LAST_NAME")); c.setCompany(rs.getString("COMPANY")); c.setPhone(rs.getString("PHONE")); c.setAddress(rs.getString("ADDRESS")); c.setCity(rs.getString("CITY")); c.setState(rs.getString("STATE")); c.setZip(rs.getString("ZIP")); c.setCountry(rs.getString("COUNTRY")); break; } conn.close(); rs.close(); } catch (SQLException e) { throw JSONException.sqlError(e); } if (c == null) { throw JSONException.noDataFound("Null set returned - no data found"); } return c; }
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 ww w.j a v a2 s. co m*/ 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:com.intuit.it.billing.data.BillingDAOImpl.java
/** * getBillingHistory is to be used to get get the billing history of a given customer. * <p/>//from w ww.j ava2 s. co m * <p/> * <b>DATABASE PROCEDURE:</b> * * @code * FUNCTION fn_get_history( * customer IN VARCHAR2, * start_date IN DATE, * end_date IN DATE, * page IN INTEGER, * records IN INTEGER ) * RETURN ref_cursor; * @endcode * <p/> * <b>DATABASE RESULT SET:</b> * <ul> * <li>ITEM_ID,</li> * <li>BILL_ITEM_NO,</li> * <li>AR_ACCOUNT_NO,</li> * <li>ACCOUNT_NO,</li> * <li>ORDER_NO,</li> * <li>ORDER_LINE_NO,</li> * <li>EVENT_TYPE,</li> * <li>CHARGE_TYPE,</li> * <li> CURRENCY,</li> * <li>CREATED_DATE,</li> * <li>BILL_DATE,</li> * <li>DUE_DATE,</li> * <li>STATUS,</li> * <li>REASON_CODE,</li> * <li>ITEM_TOTAL,</li> * <li>ITEM_DUE,</li> * <li>ITEM_DISPUTED,</li> * <li>ITEM_BASE,</li> * <li>ITEM_TAX,</li> * <li>ITEM_DESCRIPTION,</li> * <li>ITEM_CODE,</li> * <li>LICENSE,</li> * <li>PAY_TYPE,</li> * <li>PAY_DESCR,</li> * <li>PAY_ACCT_TYPE, * <li>PAY_PSON,</li> * <li>QUANTITY </li> * </ul> * * @param customer : The Customer.accountNo of the customer we want history for * @param startDate : The starting date of the allocation - to be merged with a billing history record set * @param endDate : The ending date of the allocation - to be merged with a billing history record set * @param skip : Starting record for server side paging * @param pageSize : How many records to retrieve * * @return A list of LineItem objects in reverse date order sort */ @Override public List<LineItem> getBillingHistory(String cust, Date startDate, Date endDate, Integer startPage, Integer pageSize) throws JSONException { List<LineItem> history = new ArrayList<LineItem>(); java.sql.Date sqlStartDate = new java.sql.Date(startDate.getTime()); java.sql.Date sqlEndDate = new java.sql.Date(endDate.getTime()); String query = "begin ? := billing_inquiry.fn_get_history( ?, ?, ?, ?, ? ); end;"; Connection conn = null; ResultSet rs = null; // DB Connection try { conn = this.getConnection(); } catch (SQLException e) { throw JSONException.sqlError(e); } catch (NamingException e) { throw JSONException.namingError(e.toString()); } try { CallableStatement stmt = conn.prepareCall(query); stmt.registerOutParameter(1, OracleTypes.CURSOR); stmt.setString(2, cust); stmt.setDate(3, sqlStartDate); stmt.setDate(4, sqlEndDate); stmt.setInt(5, startPage); stmt.setInt(6, pageSize); stmt.execute(); rs = (ResultSet) stmt.getObject(1); while (rs.next()) { LineItem l = new LineItem(); l.setRowId(rs.getInt("ROW_ID")); l.setBaseAmount(rs.getBigDecimal("ITEM_BASE")); l.setItemTotal(rs.getBigDecimal("ITEM_TOTAL")); l.setItemDue(rs.getBigDecimal("ITEM_DUE")); l.setItemDisputed(rs.getBigDecimal("ITEM_DISPUTED")); l.setTaxAmount(rs.getBigDecimal("ITEM_TAX")); l.setBillDate(rs.getTimestamp("BILL_DATE")); l.setBillItemNo(rs.getString("BILL_ITEM_NO")); l.setBillTo(rs.getString("AR_ACCOUNT_NO")); l.setChargeType(rs.getString("CHARGE_TYPE")); l.setCreatedDate(rs.getTimestamp("CREATED_DATE")); l.setCurrency(rs.getString("CURRENCY")); l.setDueDate(rs.getTimestamp("DUE_DATE")); l.setEventType(rs.getString("EVENT_TYPE")); l.setItemCode(rs.getString("ITEM_CODE")); l.setItemDescription(rs.getString("ITEM_DESCRIPTION")); l.setLicense(rs.getString("LICENSE")); l.setItemID(rs.getString("ITEM_ID")); l.setOrderLine(rs.getString("ORDER_LINE_NO")); l.setOrderNo(rs.getString("ORDER_NO")); l.setPayAccountType(rs.getString("PAY_ACCT_TYPE")); l.setPayDescription(rs.getString("PAY_DESCR")); l.setPayType(rs.getString("PAY_TYPE")); l.setpSON(rs.getString("PAY_PSON")); l.setQuantity(rs.getInt("QUANTITY")); l.setReasonCode(rs.getString("REASON_CODE")); l.setStatus(rs.getInt("STATUS")); history.add(l); } conn.close(); rs.close(); } catch (SQLException e) { throw JSONException.sqlError(e); } if (history == null || history.isEmpty()) { throw JSONException.noDataFound("Null set returned - no data found"); } return history; }
From source file:com.toxind.benchmark.thrid.ibatis.sqlmap.engine.execution.SqlExecutor.java
private void retrieveOutputParameters(StatementScope statementScope, CallableStatement cs, ParameterMapping[] mappings, Object[] parameters, RowHandlerCallback callback) throws SQLException { for (int i = 0; i < mappings.length; i++) { ParameterMapping mapping = ((ParameterMapping) mappings[i]); if (mapping.isOutputAllowed()) { if ("java.sql.ResultSet".equalsIgnoreCase(mapping.getJavaTypeName())) { ResultSet rs = (ResultSet) cs.getObject(i + 1); ResultMap resultMap;/*from ww w . j a v a2s. c o m*/ if (mapping.getResultMapName() == null) { resultMap = statementScope.getResultMap(); handleOutputParameterResults(statementScope, resultMap, rs, callback); } else { SqlMapClientImpl client = (SqlMapClientImpl) statementScope.getSession().getSqlMapClient(); resultMap = client.getDelegate().getResultMap(mapping.getResultMapName()); DefaultRowHandler rowHandler = new DefaultRowHandler(); RowHandlerCallback handlerCallback = new RowHandlerCallback(resultMap, null, rowHandler); handleOutputParameterResults(statementScope, resultMap, rs, handlerCallback); parameters[i] = rowHandler.getList(); } rs.close(); } else { parameters[i] = mapping.getTypeHandler().getResult(cs, i + 1); } } } }
From source file:com.intuit.it.billing.data.BillingDAOImpl.java
/** * getCustomerList//w w w . ja v a 2 s. co m * * <p/> * <p/> * <b>DATABASE PROCEDURE:</b> * * @code *FUNCTION fn_search_customers * ( * phone IN VARCHAR2, * first_name IN VARCHAR2, * last_name IN VARCHAR2, * company IN VARCHAR2, * cc_num IN VARCHAR2, * eft_num IN VARCHAR2, * records IN INTEGER * ) * RETURN ref_cursor; * @endcode * * <p/> * <b>DATABASE RESULT SET:</b> * <ul> * <li>ACCOUNT_NO,</li> * <li>FIRST_NAME,</li> * <li>LAST_NAME,</li> * <li>COMPANY,</li> * <li>PHONE,</li> * <li>ADDRESS,</li> * <li>CITY,</li> * <li>STATE,</li> * <li>ZIP,</li> * <li>COUNTRY </li> * </ul> * * @param phone - The customer's phone number * @param firstName - A wild-carded first name * @param lastName - A wild-carded last name * @param company - A wild-carded company name * @param ccNum - A four digit last-four of a credit card * @param eftNum - A four digit last-four of a bank account number * @param pageSize : How many records to retrieve * * @return A list of Customer objects in lastname, company alphabetical order * - if rows returned is greater than pageSize will not return TOO MANY rows erros * */ @Override public List<Customer> getCustomerList(String phone, String firstName, String lastName, String company, String ccNum, String eftNum, Integer pageSize) throws JSONException { Integer startPage = 1; List<Customer> customers = new ArrayList<Customer>(); String query = "begin ? := billing_inquiry.fn_search_customers( ?, ?, ?, ?, ?, ?, ?, ? ); end;"; Connection conn = null; ResultSet rs = null; // DB Connection try { conn = this.getConnection(); } catch (SQLException e) { throw JSONException.sqlError(e); } catch (NamingException e) { throw JSONException.namingError(e.toString()); } try { CallableStatement stmt = conn.prepareCall(query); stmt.registerOutParameter(1, OracleTypes.CURSOR); stmt.setString(2, phone); stmt.setString(3, firstName); stmt.setString(4, lastName); stmt.setString(5, company); stmt.setString(6, ccNum); stmt.setString(7, eftNum); stmt.setInt(8, startPage); stmt.setInt(9, pageSize); stmt.execute(); rs = (ResultSet) stmt.getObject(1); while (rs.next()) { Customer c = new Customer(); c.setAccountNo(rs.getString("ACCOUNT_NO")); c.setFirstName(rs.getString("FIRST_NAME")); c.setLastName(rs.getString("LAST_NAME")); c.setCompany(rs.getString("COMPANY")); c.setPhone(rs.getString("PHONE")); c.setAddress(rs.getString("ADDRESS")); c.setCity(rs.getString("CITY")); c.setState(rs.getString("STATE")); c.setZip(rs.getString("ZIP")); c.setCountry(rs.getString("COUNTRY")); customers.add(c); } conn.close(); rs.close(); } catch (SQLException e) { throw JSONException.sqlError(e); } if (customers == null || customers.isEmpty()) { throw JSONException.noDataFound("Null set returned - no data found"); } return customers; }
From source file:com.wabacus.system.dataset.sqldataset.GetDataSetByStoreProcedure.java
public Object getDataSet(ReportRequest rrequest, ReportBean rbean, Object typeObj, String sp, List<ConditionBean> lstConditionBeans, String datasource) { if (rbean.getInterceptor() != null) { Object obj = rbean.getInterceptor().beforeLoadData(rrequest, rbean, typeObj, sp); if (!(obj instanceof String)) return obj; sp = (String) obj;/*from w w w.ja v a 2 s . c o m*/ } if (Config.show_sql) log.info("Execute sql: " + sp); CallableStatement cstmt = null; try { if (datasource == null || datasource.trim().equals("")) datasource = rbean.getSbean().getDatasource(); cstmt = rrequest.getConnection(datasource).prepareCall(sp); AbsDatabaseType dbtype = rrequest.getDbType(datasource); VarcharType varcharObj = (VarcharType) Config.getInstance().getDataTypeByClass(VarcharType.class); IDataType datatypeObj; int idx = 1; if (lstConditionBeans != null && lstConditionBeans.size() > 0) {//?? for (ConditionBean cbTmp : lstConditionBeans) { datatypeObj = cbTmp.getDatatypeObj(); if (datatypeObj == null) datatypeObj = varcharObj; datatypeObj.setPreparedStatementValue(idx++, cbTmp.getConditionValue(rrequest, -1), cstmt, dbtype); } } if (dbtype instanceof Oracle) { cstmt.registerOutParameter(idx, OracleTypes.CURSOR); } rrequest.addUsedStatement(cstmt); cstmt.executeQuery(); ResultSet rs = null; if (dbtype instanceof Oracle) { rs = (ResultSet) cstmt.getObject(idx); } else { rs = cstmt.getResultSet(); } return rs; } catch (SQLException e) { throw new WabacusRuntimeException( "??" + rbean.getPath() + "?SQL" + sp + "", e); } }
From source file:com.mimp.hibernate.HiberNna.java
public String get_Last_numero_expediente() { Session session = sessionFactory.getCurrentSession(); Work work;/*from ww w .j ava 2s .c o m*/ work = new Work() { @Override public void execute(Connection connection) throws SQLException { numero_last = null; ResultSet temp_numero; String hql = "{call HN_GET_LAST_EXPEDIENTE_NNA(?)}"; CallableStatement statement = connection.prepareCall(hql); statement.registerOutParameter(1, OracleTypes.CURSOR); statement.execute(); temp_numero = (ResultSet) statement.getObject(1); while (temp_numero.next()) { numero_last = temp_numero.getString(2); } temp_numero.close(); statement.close(); } }; session.doWork(work); return numero_last; }
From source file:com.mimp.hibernate.HiberNna.java
public ArrayList<ExpedienteNna> listaExpNna() { Session session = sessionFactory.getCurrentSession(); final ArrayList<ExpedienteNna> allExpNna = new ArrayList(); Work work = new Work() { @Override/*from www. j a v a 2 s. c om*/ public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; String hql = "{call HN_GET_EXPEDIENTE_NNA(?)}"; CallableStatement statement = connection.prepareCall(hql); statement.registerOutParameter(1, OracleTypes.CURSOR); statement.execute(); temp = (ResultSet) statement.getObject(1); while (temp.next()) { expnna = new ExpedienteNna(); expnna.setIdexpedienteNna(temp.getShort(1)); expnna.setNumero(temp.getString(4)); expnna.setFechaIngreso(temp.getDate(5)); expnna.setHt(temp.getString(6)); expnna.setNExpTutelar(temp.getString(7)); expnna.setProcTutelar(temp.getString(8)); expnna.setFichaIntegral(temp.getShort(9)); expnna.setComentarios(temp.getString(10)); expnna.setRespLegalNombre(temp.getString(11)); expnna.setRespLegalP(temp.getString(12)); expnna.setRespLegalM(temp.getString(13)); expnna.setRespPsicosocialNombre(temp.getString(14)); expnna.setRespPiscosocialP(temp.getString(15)); expnna.setRespPsicosocialM(temp.getString(16)); expnna.setEstado(temp.getString(17)); expnna.setFechaEstado(temp.getDate(18)); expnna.setAdoptable(temp.getShort(19)); expnna.setFechaResolCons(temp.getDate(20)); expnna.setNacional(temp.getShort(21)); expnna.setDiagnostico(temp.getString(22)); expnna.setCodigoReferencia(temp.getString(23)); expnna.setNActual(temp.getString(24)); expnna.setApellidopActual(temp.getString(25)); expnna.setApellidomActual(temp.getString(26)); expnna.setObservaciones(temp.getString(27)); expnna.setFechaInvTutelar(temp.getDate(28)); allExpNna.add(expnna); } temp.close(); statement.close(); } }; session.doWork(work); return allExpNna; }
From source file:com.mimp.hibernate.HiberNna.java
public InformeNna InformeExpNna(Long idInforme) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();// w w w. j a va 2s.co m final Long id = idInforme; final InformeNna temp = new InformeNna(); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { String hql = "{call HN_GET_INF_EVAL(?,?)}"; CallableStatement statement = connection.prepareCall(hql); statement.setLong(1, id); statement.registerOutParameter(2, OracleTypes.CURSOR); statement.execute(); ResultSet rs = (ResultSet) statement.getObject(2); if (rs.next()) { temp.setIdinformeNna(rs.getLong("IDINFORME_NNA")); temp.setNumero(rs.getString("NUMERO")); temp.setFecha(rs.getDate("FECHA")); temp.setResultado(rs.getString("RESULTADO")); temp.setObservaciones(rs.getString("OBSERVACIONES")); } rs.close(); statement.close(); } }; session.doWork(work); return temp; }
From source file:com.mimp.hibernate.HiberNna.java
public ArrayList<InformeNna> listaInformesExpNna(Long idExpNna) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();/* www . j av a2 s. c o m*/ final Long expNna = idExpNna; final ArrayList<InformeNna> lista = new ArrayList(); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { String hql = "{call HN_LIST_INF_EVAL(?,?)}"; CallableStatement statement = connection.prepareCall(hql); statement.setLong(1, expNna); statement.registerOutParameter(2, OracleTypes.CURSOR); statement.execute(); ResultSet rs = (ResultSet) statement.getObject(2); while (rs.next()) { InformeNna tempInf = new InformeNna(); tempInf.setIdinformeNna(rs.getLong("IDINFORME_NNA")); tempInf.setNumero(rs.getString("NUMERO")); tempInf.setFecha(rs.getDate("FECHA")); lista.add(tempInf); } rs.close(); statement.close(); } }; session.doWork(work); return lista; }