List of usage examples for java.sql Date valueOf
@SuppressWarnings("deprecation") public static Date valueOf(LocalDate date)
From source file:com.wso2telco.dep.reportingservice.northbound.NbHostObjectUtils.java
/** * Apply tax for block charging.// www .j av a2 s . c om * * @param CatEntry the cat entry * @param rate the rate * @param year the year * @param month the month * @throws Exception */ private static void applyTaxForBlockCharging(Map.Entry<CategoryCharge, BilledCharge> CatEntry, ChargeRate rate, String year, String month) throws Exception { TaxDAO taxDAO = new TaxDAO(); List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList()); CategoryCharge categorycharge = CatEntry.getKey(); BilledCharge billed = CatEntry.getValue(); BigDecimal totalTax = BigDecimal.ZERO; Date billingDate = Date.valueOf(year + "-" + month + "-01"); // start of // the // month for (Tax tax : taxList) { // select the taxes applicable at the billing date if (!billingDate.before(tax.getEffective_from()) && !billingDate.after(tax.getEffective_to())) { // totalTax += taxFraction x charge totalTax = totalTax.add(tax.getValue().multiply(billed.getPrice())); } } CatEntry.getValue().setTax(totalTax); }
From source file:com.wso2telco.dep.reportingservice.southbound.SbHostObjectUtils.java
/** * Apply tax for block charging.// ww w. j av a 2s . com * * @param CatEntry the cat entry * @param rate the rate * @param year the year * @param month the month * @throws Exception */ private static void applyTaxForBlockCharging(Map.Entry<CategoryCharge, BilledCharge> CatEntry, ChargeRate rate, String year, String month) throws Exception { TaxDAO taxDAO = new TaxDAO(); List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList()); CategoryCharge categorycharge = CatEntry.getKey(); BilledCharge billed = CatEntry.getValue(); BigDecimal totalTax = BigDecimal.ZERO; Date billingDate = Date.valueOf(year + "-" + month + "-01"); // start of // the // month for (Tax tax : taxList) { // select the taxes applicable at the billing date if (!billingDate.before(tax.getEffective_from()) && !billingDate.after(tax.getEffective_to())) { totalTax = totalTax.add(tax.getValue().multiply(billed.getPrice())); } } CatEntry.getValue().setTax(totalTax); }
From source file:org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils.java
public static Date getDate(Object o, PrimitiveObjectInspector oi) { if (o == null) { return null; }//from w ww. j a va 2 s.c o m Date result = null; switch (oi.getPrimitiveCategory()) { case VOID: result = null; break; case STRING: StringObjectInspector soi = (StringObjectInspector) oi; String s = soi.getPrimitiveJavaObject(o).trim(); try { result = Date.valueOf(s); } catch (IllegalArgumentException e) { result = null; } break; case CHAR: case VARCHAR: { try { String val = getString(o, oi).trim(); result = Date.valueOf(val); } catch (IllegalArgumentException e) { result = null; } break; } case DATE: result = ((DateObjectInspector) oi).getPrimitiveWritableObject(o).get(); break; case TIMESTAMP: result = DateWritable .timeToDate(((TimestampObjectInspector) oi).getPrimitiveWritableObject(o).getSeconds()); break; default: throw new RuntimeException("Cannot convert to Date from: " + oi.getTypeName()); } return result; }
From source file:ui.Analyze.java
private Component buatPermintaan(LocalDate l) throws SQLException { org.jfree.data.general.DefaultPieDataset data = new org.jfree.data.general.DefaultPieDataset(); java.sql.PreparedStatement p = d.getPS( "select detjual.brg,sum(detjual.jum)as qty from jual inner join detjual where jual.tgl>=? and " + "jual.tgl<? group by detjual.brg"); p.setDate(1, Date.valueOf(l)); p.setDate(2, Date.valueOf(l.plusMonths(1))); java.sql.ResultSet r = p.executeQuery(); while (r.next()) data.setValue(getNamaBrg(r.getString("brg")), r.getDouble("qty")); r.close();// w ww. j a v a2 s. c om p.close(); return new org.jfree.chart.ChartPanel(ChartFactory.createPieChart("PERMINTAAN", data, true, true, false)); }
From source file:ui.Analyze.java
private Number getUntung(LocalDate l2) throws SQLException { org.joda.money.Money m = org.joda.money.Money.zero(CurrencyUnit.of("IDR")); java.sql.PreparedStatement p = d.getPS("select total from jual where tgl=?"); p.setDate(1, Date.valueOf(l2)); java.sql.ResultSet r = p.executeQuery(); while (r.next()) m = m.plus(org.joda.money.Money.parse(r.getString("total"))); r.close();/*from w ww.ja v a2 s . co m*/ p.close(); return m.getAmount().longValue(); }
From source file:ui.Analyze.java
private Number getRugi(LocalDate l2) throws SQLException { double dou = 0; java.sql.PreparedStatement p = d.getPS("select sum(sat*jum)as oke from memasok where tgl=?"); p.setDate(1, Date.valueOf(l2)); java.sql.ResultSet r = p.executeQuery(); if (r.next()) dou = r.getDouble("oke"); r.close();/*from w w w.java 2 s . co m*/ p.close(); return dou; }
From source file:ui.Analyze.java
private void genaratePermintaan(LocalDate awal, LocalDate akhir) throws SQLException { org.jfree.data.general.DefaultPieDataset data = new org.jfree.data.general.DefaultPieDataset(); javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel( new String[] { "Nama Barang", "Jumlah" }, 0) { @Override//www. j a va 2 s . c o m public boolean isCellEditable(int row, int column) { return false; } }; tblMinta.setModel(m); java.sql.PreparedStatement p = d.getPS( "select detjual.brg,sum(detjual.jum)as qty from jual left join detjual on jual.nota=detjual.nota " + "where jual.tgl>=? and " + "jual.tgl<=? group by detjual.brg"); p.setDate(1, Date.valueOf(awal)); p.setDate(2, Date.valueOf(akhir)); java.sql.ResultSet r = p.executeQuery(); while (r.next()) { String brg = r.getString("brg"); double qty = r.getDouble("qty"); data.setValue(brg, qty); m.addRow(new String[] { brg, "" + qty }); } r.close(); p.close(); org.jfree.chart.ChartPanel cp = new org.jfree.chart.ChartPanel( ChartFactory.createPieChart("Permintaan", data, true, true, false)); cp.setSize(pnlMinta.getSize()); if (0 < pnlMinta.getComponentCount()) pnlMinta.removeAll(); pnlMinta.add(cp); }
From source file:massbank.DatabaseManager.java
public void persistAccessionFile(Record acc, boolean bulk) { // this.openConnection(); // String insertCompound = "INSERT INTO COMPOUND VALUES(?,?,?,?,?,?,?,?)"; // PreparedStatement stmnt = con.prepareStatement(insertCompound); Integer conId = -1;// w w w.j a v a 2 s . c o m try { String sql = "SELECT ID FROM CONTRIBUTOR WHERE SHORT_NAME = ?"; PreparedStatement stmnt = con.prepareStatement(sql); stmnt.setString(1, acc.CONTRIBUTOR()); ResultSet res = stmnt.executeQuery(); if (res.next()) { conId = res.getInt(1); } } catch (SQLException e1) { e1.printStackTrace(); } if (conId == -1) { try { String sql = "INSERT INTO CONTRIBUTOR (ACRONYM, SHORT_NAME, FULL_NAME) VALUES (NULL,?,NULL)"; PreparedStatement stmnt = con.prepareStatement(sql); stmnt.setString(1, acc.CONTRIBUTOR()); stmnt.executeUpdate(); } catch (SQLException e1) { e1.printStackTrace(); } try { String sql = "SELECT ID FROM CONTRIBUTOR WHERE SHORT_NAME = ?"; PreparedStatement stmnt = con.prepareStatement(sql); stmnt.setString(1, acc.CONTRIBUTOR()); ResultSet res = stmnt.executeQuery(); if (res.next()) { conId = res.getInt(1); } } catch (SQLException e1) { e1.printStackTrace(); } } try { //System.out.println(System.nanoTime()); statementInsertCompound.setNull(1, java.sql.Types.INTEGER); statementInsertCompound.setString(2, acc.CH_FORMULA()); statementInsertCompound.setDouble(3, acc.CH_EXACT_MASS()); statementInsertCompound.setString(4, acc.CH_SMILES()); statementInsertCompound.setString(5, acc.CH_IUPAC()); // TODO support CH$CDK_DEPICT_SMILES // TODO support CH$CDK_DEPICT_GENERIC_SMILES // TODO support CH$CDK_DEPICT_STRUCTURE_SMILES // if (acc.get("CH$CDK_DEPICT_SMILES").size() != 0) { // statementInsertCompound.setString(6, acc.get("CH$CDK_DEPICT_SMILES").get(0)[2]); // } else { statementInsertCompound.setNull(6, java.sql.Types.VARCHAR); // } // if (acc.get("CH$CDK_DEPICT_GENERIC_SMILES").size() != 0) { // statementInsertCompound.setString(7, acc.get("CH$CDK_DEPICT_GENERIC_SMILES").get(0)[2]); // } else { statementInsertCompound.setNull(7, java.sql.Types.VARCHAR); // } // if (acc.get("CH$CDK_DEPICT_STRUCTURE_SMILES").size() != 0) { // statementInsertCompound.setString(8, acc.get("CH$CDK_DEPICT_STRUCTURE_SMILES").get(0)[2]); // } else { statementInsertCompound.setNull(8, java.sql.Types.VARCHAR); // } statementInsertCompound.executeUpdate(); ResultSet set = statementInsertCompound.getGeneratedKeys(); set.next(); int compoundId = set.getInt("ID"); //System.out.println(System.nanoTime()); int compoundClassId; // String insertCompoundClass = "INSERT INTO COMPOUND_CLASS VALUES(?,?,?,?)"; // stmnt = con.prepareStatement(insertCompoundClass); for (String el : acc.CH_COMPOUND_CLASS()) { statementInsertCompound_Class.setNull(1, java.sql.Types.INTEGER); statementInsertCompound_Class.setString(2, null); statementInsertCompound_Class.setString(3, null); statementInsertCompound_Class.setString(4, el); statementInsertCompound_Class.executeUpdate(); set = statementInsertCompound_Class.getGeneratedKeys(); set.next(); compoundClassId = set.getInt("ID"); // String insertCompoundCompoundClass = "INSERT INTO COMPOUND_COMPOUND_CLASS VALUES(?,?)"; // stmnt = con.prepareStatement(insertCompoundCompoundClass); statementInsertCompound_Compound_Class.setInt(1, compoundId); statementInsertCompound_Compound_Class.setInt(2, compoundClassId); statementInsertCompound_Compound_Class.executeUpdate(); } //System.out.println(System.nanoTime()); int nameId; // String insertName = "INSERT INTO NAME VALUES(?,?)"; // stmnt = con.prepareStatement(insertName); for (String el : acc.CH_NAME()) { statementInsertName.setNull(1, java.sql.Types.INTEGER); statementInsertName.setString(2, el); try { statementInsertName.executeUpdate(); set = statementInsertName.getGeneratedKeys(); set.next(); nameId = set.getInt("ID"); // String insertCompoundName = "INSERT INTO COMPOUND_NAME VALUES(?,?)"; // stmnt = con.prepareStatement(insertCompoundName); statementInsertCompound_Name.setInt(1, compoundId); statementInsertCompound_Name.setInt(2, nameId); statementInsertCompound_Name.executeUpdate(); } catch (SQLException e) { if (e.getErrorCode() == 1062) { PreparedStatement retrieveIdForName = con .prepareStatement("SELECT ID FROM NAME WHERE CH_NAME = ?"); retrieveIdForName.setString(1, el); set = retrieveIdForName.executeQuery(); set.next(); nameId = set.getInt("ID"); statementInsertCompound_Name.setInt(1, compoundId); statementInsertCompound_Name.setInt(2, nameId); statementInsertCompound_Name.executeUpdate(); } else { this.closeConnection(); throw e; // e.printStackTrace(); // nameId = -1; } } } //System.out.println(System.nanoTime()); // String insertChLink = "INSERT INTO CH_LINK VALUES(?,?,?)"; // stmnt = con.prepareStatement(insertChLink); for (Pair<String, String> el : acc.CH_LINK()) { statementInsertCH_LINK.setInt(1, compoundId); statementInsertCH_LINK.setString(2, el.getLeft()); statementInsertCH_LINK.setString(3, el.getRight()); // statementInsertCH_LINK.executeUpdate(); statementInsertCH_LINK.addBatch(); } if (!bulk) { statementInsertCH_LINK.executeBatch(); } //System.out.println(System.nanoTime()); int sampleId = -1; statementInsertSAMPLE.setNull(1, java.sql.Types.INTEGER); if (acc.SP_SCIENTIFIC_NAME() != null) { statementInsertSAMPLE.setString(2, acc.SP_SCIENTIFIC_NAME()); } else { statementInsertSAMPLE.setNull(2, java.sql.Types.VARCHAR); } if (acc.SP_LINEAGE() != null) { statementInsertSAMPLE.setString(3, acc.SP_LINEAGE()); } else { statementInsertSAMPLE.setNull(3, java.sql.Types.VARCHAR); } if (acc.SP_SCIENTIFIC_NAME() != null && acc.SP_LINEAGE() != null) { statementInsertSAMPLE.executeUpdate(); set = statementInsertSAMPLE.getGeneratedKeys(); set.next(); sampleId = set.getInt("ID"); } //System.out.println(System.nanoTime()); for (Pair<String, String> el : acc.SP_LINK()) { statementInsertSP_LINK.setInt(1, sampleId); statementInsertSP_LINK.setString(2, el.getLeft() + " " + el.getRight()); // statementInsertSP_LINK.executeUpdate(); statementInsertSP_LINK.addBatch(); } if (!bulk) { statementInsertSP_LINK.executeBatch(); } //System.out.println(System.nanoTime()); for (String el : acc.SP_SAMPLE()) { statementInsertSP_SAMPLE.setInt(1, sampleId); statementInsertSP_SAMPLE.setString(2, el); // statementInsertSP_SAMPLE.executeUpdate(); statementInsertSP_SAMPLE.addBatch(); } if (!bulk) { statementInsertSP_SAMPLE.executeBatch(); } //System.out.println(System.nanoTime()); statementInsertINSTRUMENT.setNull(1, java.sql.Types.INTEGER); statementInsertINSTRUMENT.setString(2, acc.AC_INSTRUMENT()); statementInsertINSTRUMENT.setString(3, acc.AC_INSTRUMENT_TYPE()); statementInsertINSTRUMENT.executeUpdate(); set = statementInsertINSTRUMENT.getGeneratedKeys(); set.next(); int instrumentId = set.getInt("ID"); //System.out.println(System.nanoTime()); statementInsertRECORD.setString(1, acc.ACCESSION()); statementInsertRECORD.setString(2, acc.RECORD_TITLE()); statementInsertRECORD.setDate(3, Date.valueOf(acc.DATE())); statementInsertRECORD.setString(4, acc.AUTHORS()); // if (acc.get("LICENSE").size() != 0) { statementInsertRECORD.setString(5, acc.LICENSE()); // } else { // statementInsertRECORD.setNull(5, java.sql.Types.VARCHAR); // } if (acc.COPYRIGHT() != null) { statementInsertRECORD.setString(6, acc.COPYRIGHT()); } else { statementInsertRECORD.setNull(6, java.sql.Types.VARCHAR); } if (acc.PUBLICATION() != null) { statementInsertRECORD.setString(7, acc.PUBLICATION()); } else { statementInsertRECORD.setNull(7, java.sql.Types.VARCHAR); } statementInsertRECORD.setInt(8, compoundId); if (sampleId > 0) { statementInsertRECORD.setInt(9, sampleId); } else { statementInsertRECORD.setNull(9, java.sql.Types.INTEGER); } statementInsertRECORD.setInt(10, instrumentId); statementInsertRECORD.setString(11, acc.AC_MASS_SPECTROMETRY_MS_TYPE()); statementInsertRECORD.setString(12, acc.AC_MASS_SPECTROMETRY_ION_MODE()); statementInsertRECORD.setString(13, acc.PK_SPLASH()); statementInsertRECORD.setInt(14, conId); statementInsertRECORD.executeUpdate(); // set = statementInsertRECORD.getGeneratedKeys(); // set.next(); String accession = acc.ACCESSION(); //System.out.println(System.nanoTime()); for (String el : acc.COMMENT()) { statementInsertCOMMENT.setString(1, accession); statementInsertCOMMENT.setString(2, el); // statementInsertCOMMENT.executeUpdate(); statementInsertCOMMENT.addBatch(); } if (!bulk) { statementInsertCOMMENT.executeBatch(); } //System.out.println(System.nanoTime()); for (Pair<String, String> el : acc.AC_MASS_SPECTROMETRY()) { statementInsertAC_MASS_SPECTROMETRY.setString(1, accession); statementInsertAC_MASS_SPECTROMETRY.setString(2, el.getLeft()); statementInsertAC_MASS_SPECTROMETRY.setString(3, el.getRight()); // statementInsertAC_MASS_SPECTROMETRY.executeUpdate(); statementInsertAC_MASS_SPECTROMETRY.addBatch(); } if (!bulk) { statementInsertAC_MASS_SPECTROMETRY.executeBatch(); } //System.out.println(System.nanoTime()); for (Pair<String, String> el : acc.AC_CHROMATOGRAPHY()) { statementInsertAC_CHROMATOGRAPHY.setString(1, accession); statementInsertAC_CHROMATOGRAPHY.setString(2, el.getLeft()); statementInsertAC_CHROMATOGRAPHY.setString(3, el.getRight()); // statementInsertAC_CHROMATOGRAPHY.executeUpdate(); statementInsertAC_CHROMATOGRAPHY.addBatch(); } if (!bulk) { statementInsertAC_CHROMATOGRAPHY.executeBatch(); } //System.out.println(System.nanoTime()); for (Pair<String, String> el : acc.MS_FOCUSED_ION()) { statementInsertMS_FOCUSED_ION.setString(1, accession); statementInsertMS_FOCUSED_ION.setString(2, el.getLeft()); statementInsertMS_FOCUSED_ION.setString(3, el.getRight()); // statementInsertMS_FOCUSED_ION.executeUpdate(); statementInsertMS_FOCUSED_ION.addBatch(); } if (!bulk) { statementInsertMS_FOCUSED_ION.executeBatch(); } //System.out.println(System.nanoTime()); for (Pair<String, String> el : acc.MS_DATA_PROCESSING()) { statementInsertMS_DATA_PROCESSING.setString(1, accession); statementInsertMS_DATA_PROCESSING.setString(2, el.getLeft()); statementInsertMS_DATA_PROCESSING.setString(3, el.getRight()); // statementInsertMS_DATA_PROCESSING.executeUpdate(); statementInsertMS_DATA_PROCESSING.addBatch(); } if (!bulk) { statementInsertMS_DATA_PROCESSING.executeBatch(); } //System.out.println(System.nanoTime()); for (List<Double> peak : acc.PK_PEAK()) { statementInsertPEAK.setString(1, accession); statementInsertPEAK.setDouble(2, peak.get(0)); statementInsertPEAK.setFloat(3, (float) (double) peak.get(1)); statementInsertPEAK.setShort(4, (short) (double) peak.get(2)); statementInsertPEAK.setNull(5, java.sql.Types.VARCHAR); // statementInsertPEAK.setNull(5, java.sql.Types.VARCHAR); // statementInsertPEAK.setNull(6, java.sql.Types.SMALLINT); // statementInsertPEAK.setNull(7, java.sql.Types.FLOAT); // statementInsertPEAK.setNull(8, java.sql.Types.FLOAT); // statementInsertPEAK.executeUpdate(); statementInsertPEAK.addBatch(); } if (!bulk) { statementInsertPEAK.executeBatch(); } //System.out.println(System.nanoTime()); List<List<String>> annotation = acc.PK_ANNOTATION(); if (annotation.size() != 0) { statementInsertANNOTATION_HEADER.setString(1, accession); statementInsertANNOTATION_HEADER.setString(2, String.join(" ", annotation.get(0))); statementInsertANNOTATION_HEADER.executeUpdate(); } for (int i = 1; i < annotation.size(); i++) { String values = String.join(" ", annotation.get(i)); Float mz = Float.parseFloat(annotation.get(i).get(0)); // values = values.substring(values.indexOf(" ")+1, values.length()); statementUpdatePEAKs.setString(1, values); statementUpdatePEAKs.setString(2, accession); statementUpdatePEAKs.setFloat(3, mz); // statementUpdatePEAK.setString(1, values.substring(0, values.indexOf(" "))); // values = values.substring(values.indexOf(" ")+1, values.length()); // statementUpdatePEAK.setShort(2, Short.parseShort(values.substring(0, values.indexOf(" ")))); // values = values.substring(values.indexOf(" ")+1, values.length()); // statementUpdatePEAK.setFloat(3, Float.parseFloat(values.substring(0, values.indexOf(" ")))); // values = values.substring(values.indexOf(" ")+1, values.length()); // statementUpdatePEAK.setFloat(4, Float.parseFloat(values.substring(0, values.length()))); // statementUpdatePEAK.setString(5, accession); // statementUpdatePEAK.setFloat(6, mz); // statementUpdatePEAK.executeUpdate(); statementUpdatePEAKs.addBatch(); } if (!bulk) { statementUpdatePEAKs.executeBatch(); } //System.out.println(System.nanoTime()); con.commit(); //System.out.println(System.nanoTime()); } catch (SQLException e) { StringBuilder tmp = new StringBuilder(); tmp.append(e.getMessage()); tmp.append("\n"); for (StackTraceElement el : e.getStackTrace()) { tmp.append(el.toString()); tmp.append("\n"); } DevLogger.printToDBLog("DB ERROR " + tmp + " for accession: " + acc.ACCESSION()); // try { // e.printStackTrace(new PrintStream(new FileOutputStream("/Users/laptop/Desktop/errors/" + acc.ACCESSION() + ".txt"))); // } catch (FileNotFoundException e1) { // //e1.printStackTrace(); // } this.closeConnection(); } catch (IndexOutOfBoundsException e) { StringBuilder tmp = new StringBuilder(); tmp.append(e.getMessage()); tmp.append("\n"); for (StackTraceElement el : e.getStackTrace()) { tmp.append(el.toString()); tmp.append("\n"); } DevLogger.printToDBLog("DB ERROR " + tmp + " for accession: " + acc.ACCESSION()); // System.out.println(acc.ACCESSION()); // System.out.println(acc.get("PK$PEAK").size()); // System.out.println(acc.get("PK$ANNOTATION").size()); // try { // e.printStackTrace(new PrintStream(new FileOutputStream("/Users/laptop/Desktop/errors/" + acc.ACCESSION() + ".txt"))); // } catch (FileNotFoundException e1) { // //e1.printStackTrace(); // } } catch (Exception e) { StringBuilder tmp = new StringBuilder(); tmp.append(e.getMessage()); tmp.append("\n"); for (StackTraceElement el : e.getStackTrace()) { tmp.append(el.toString()); tmp.append("\n"); } DevLogger.printToDBLog("DB ERROR " + tmp + " for accession: " + acc.ACCESSION()); // try { // e.printStackTrace(new PrintStream(new FileOutputStream("/Users/laptop/Desktop/errors/" + acc.ACCESSION() + ".txt"))); // } catch (FileNotFoundException e1) { // //e1.printStackTrace(); // } this.closeConnection(); } // this.closeConnection(); }
From source file:rentalshop.Window.java
private Date stringToDate(String s) { Date date = Date.valueOf(s); // Calendar cal = new GregorianCalendar(); // cal.set(Integer.valueOf(from[0]), Integer.valueOf(from[1]), Integer.valueOf(from[2])); // Date date = new Date(cal.getTimeInMillis()); return date;/* w w w.ja va2 s . c om*/ }
From source file:org.wso2.ws.dataservice.DBUtils.java
public static PreparedStatement getProcessedPreparedStatement(HashMap inputs, HashMap params, HashMap paramOrder, HashMap originalParamNames, HashMap paramTypes, Connection conn, String sqlStatement, String callee, String serviceName) throws AxisFault { String paramName = null;//from w ww. j av a 2 s . c om String originalParamName = null; String sqlType = null; String value = null; String paramType = null; log.debug("[" + serviceName + "] Processing prepared statement for SQL " + sqlStatement); Set paramNames = params.keySet(); Object pramNameArray[] = paramNames.toArray(); try { PreparedStatement sqlQuery = null; if ("SQL".equals(callee)) { sqlQuery = conn.prepareStatement(sqlStatement); //SQL expects parameters, but not params set in config file if (sqlStatement.indexOf("?") > -1 && pramNameArray.length == 0) { throw new AxisFault( "[" + serviceName + "] SQL : " + sqlStatement + " expects one or more parameters. " + "But none is mentioned in the configuration file."); } } else if ("STORED-PROCEDURE".equals(callee)) { sqlQuery = conn.prepareCall(sqlStatement); } for (int i = 0; i < pramNameArray.length; i++) { paramName = (String) paramOrder.get(new Integer(i + 1)); originalParamName = (String) originalParamNames.get(new Integer(i + 1)); sqlType = (String) params.get(paramName); paramType = (String) paramTypes.get(paramName); value = (String) inputs.get(paramName); log.debug("[" + serviceName + "] Param name : " + paramName + " SQL Type : " + sqlType + " Value : " + value); if ("IN".equals(paramType) || "INOUT".equals(paramType)) { if (value == null || value.trim().length() == 0) { log.error("[" + serviceName + "] Empty value found for parameter : " + originalParamName); throw new AxisFault( "[" + serviceName + "] Empty value found for parameter : " + originalParamName); } } //work-a-round for setting NULL if ("NULL".equalsIgnoreCase(value)) { value = null; } //TODO : work-a-round for setting space if (sqlType == null) { // Defaults to string if ("IN".equals(paramType)) { sqlQuery.setString(i + 1, value); } else if ("INOUT".equals(paramType)) { sqlQuery.setString(i + 1, value); ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.VARCHAR); } else { ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.VARCHAR); } } else if (DBConstants.DataTypes.INTEGER.equals(sqlType)) { if ("IN".equals(paramType)) { if ("SQL".equals(callee)) { sqlQuery.setInt(i + 1, Integer.parseInt(value)); } else { ((CallableStatement) sqlQuery).setInt(i + 1, Integer.parseInt(value)); } } else if ("INOUT".equals(paramType)) { ((CallableStatement) sqlQuery).setInt(i + 1, Integer.parseInt(value)); ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.INTEGER); } else { ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.INTEGER); } } else if (DBConstants.DataTypes.STRING.equals(sqlType)) { if ("IN".equals(paramType)) { if ("SQL".equals(callee)) { sqlQuery.setString(i + 1, value); } else { ((CallableStatement) sqlQuery).setString(i + 1, value); } } else if ("INOUT".equals(paramType)) { ((CallableStatement) sqlQuery).setString(i + 1, value); ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.VARCHAR); } else { ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.VARCHAR); } } else if (DBConstants.DataTypes.DOUBLE.equals(sqlType)) { if ("IN".equals(paramType)) { if ("SQL".equals(callee)) { sqlQuery.setDouble(i + 1, Double.parseDouble(value)); } else { ((CallableStatement) sqlQuery).setDouble(i + 1, Double.parseDouble(value)); } } else if ("INOUT".equals(paramType)) { ((CallableStatement) sqlQuery).setDouble(i + 1, Double.parseDouble(value)); ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.DOUBLE); } else { ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.DOUBLE); } } else if (DBConstants.DataTypes.DATE.equals(sqlType)) { try { //Only yyyy-MM-dd part is needed String modifiedValue = value.substring(0, 10); if ("IN".equals(paramType)) { if ("SQL".equals(callee)) { sqlQuery.setDate(i + 1, Date.valueOf(modifiedValue)); } else { ((CallableStatement) sqlQuery).setDate(i + 1, Date.valueOf(modifiedValue)); } } else if ("INOUT".equals(paramType)) { ((CallableStatement) sqlQuery).setDate(i + 1, Date.valueOf(modifiedValue)); ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.DATE); } else { ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.DATE); } } catch (IllegalArgumentException e) { log.error("Incorrect date format(" + value + ") for parameter : " + paramName, e); throw new AxisFault("Incorrect date format for parameter : " + paramName + ".Date should be in yyyy-mm-dd format.", e); } } else if (DBConstants.DataTypes.TIMESTAMP.equals(sqlType)) { Timestamp timestamp = getTimestamp(value, paramName); if ("IN".equals(paramType)) { if ("SQL".equals(callee)) { sqlQuery.setTimestamp(i + 1, timestamp); } else { ((CallableStatement) sqlQuery).setTimestamp(i + 1, timestamp); } } else if ("INOUT".equals(paramType)) { ((CallableStatement) sqlQuery).setTimestamp(i + 1, timestamp); ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.TIMESTAMP); } else { ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.TIMESTAMP); } } else if (DBConstants.DataTypes.TIME.equals(sqlType)) { Time time = getTime(value, paramName); if ("IN".equals(paramType)) { if ("SQL".equals(callee)) { sqlQuery.setTime(i + 1, time); } else { ((CallableStatement) sqlQuery).setTime(i + 1, time); } } else if ("INOUT".equals(paramType)) { ((CallableStatement) sqlQuery).setTime(i + 1, time); ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.TIME); } else { ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.TIME); } } else { log.error("[" + serviceName + "] Unsupported data type : " + sqlType + " as input parameter."); throw new AxisFault("[" + serviceName + "] Found Unsupported data type : " + sqlType + " as input parameter."); } } return sqlQuery; } catch (NumberFormatException e) { log.error("[" + serviceName + "] Incorrect value found for parameter : " + originalParamName, e); throw new AxisFault("[" + serviceName + "] Incorrect value found for parameter : " + originalParamName, e); } catch (SQLException e) { log.error("[" + serviceName + "] Error occurred while preparing prepared statement for sql : " + sqlStatement, e); throw new AxisFault("[" + serviceName + "] Error occurred while preparing prepared statement for sql : " + sqlStatement, e); } }