I have Postgres that works when on it own, but doesn't work when integrated into java and called on idempiere. I'm looking for suggestion.
I get the ff error:
caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "00"
Position: 1055; State=42601; ErrorCode=0
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:120)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:384)
at jdk.internal.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.compiere.db.StatementProxy.invoke(StatementProxy.java:130)
at com.sun.proxy.$Proxy11.executeUpdate(Unknown Source)
at org.compiere.util.DB.executeUpdate(DB.java:1039)
at org.compiere.util.DB.executeUpdate(DB.java:898)
at org.compiere.util.DB.executeUpdate(DB.java:885)
at ice.enterprise.base.report.StockAgingReport.createDetailLines(StockAgingReport.java:145)
at ice.enterprise.base.report.StockAgingReport.doIt(StockAgingReport.java:72)
at org.compiere.process.SvrProcess.process(SvrProcess.java:201)
at org.compiere.process.SvrProcess.startProcess(SvrProcess.java:147)
at org.adempiere.util.ProcessUtil.startJavaProcess(ProcessUtil.java:173)
at org.compiere.apps.AbstractProcessCtl.startProcess(AbstractProcessCtl.java:467)
at org.compiere.apps.AbstractProcessCtl.run(AbstractProcessCtl.java:235)
15:21:49.994===========> DataEngine.loadPrintData: null - ERROR: column "levelno" does not exist
Position: 924
SQL=SELECT T_ReportStockAgeing.CurrentCost,T_ReportStockAgeing.Date1,T_ReportStockAgeing_ICE.Description,T_ReportStockAgeing.OnHand,(SELECT NVL(AD_PInstance.Name,'-1') ||'_'|| NVL(CAST (AD_PInstance.AD_PInstance_ID AS Text),'-1') ||'_'|| NVL((SELECT NVL(AD_Process.Name,'-1') ||'_'|| NVL(AD_Process.Value,'-1') FROM AD_Process WHERE AD_PInstance.AD_Process_ID=AD_Process.AD_Process_ID),'-1') FROM AD_PInstance WHERE T_ReportStockAgeing.AD_PInstance_ID=AD_PInstance.AD_PInstance_ID) AS AAD_PInstance_ID,T_ReportStockAgeing.AD_PInstance_ID AS AD_PInstance_ID,T_ReportStockAgeing.ProductCode,T_ReportStockAgeing.Qty1,T_ReportStockAgeing.Qty2,T_ReportStockAgeing.Qty3,T_ReportStockAgeing.Qty4,T_ReportStockAgeing.Value1,T_ReportStockAgeing.Valu2,T_ReportStockAgeing.Value3,T_ReportStockAgeing.Value4,T_ReportStockAgeing_ICE.T_ReportStockAgeing_ICE_UU,LevelNo FROM T_ReportStockAgeing_ICE WHERE T_ReportStockAgeing_ICE.AD_PInstance_ID=2109500 [136]
15:21:50.030===========> AbstractProcessDialog.doRun: org.postgresql.util.PSQLException: ERROR: column "levelno" does not exist
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.logging.Level;
import org.compiere.print.MPrintFormat;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
public class StockAgingReport extends SvrProcess {
private int p_AD_Org_ID = 0;
private int p_AD_Client_ID = 0;
private int p_C_AcctSchema_ID = 0;
private int p_M_Product_Category_ID = 0;
private Timestamp p_Date = null;
private long m_start = System.currentTimeMillis();
#Override
protected void prepare() {
StringBuffer sb = new StringBuffer ("Record_ID=")
.append(getRecord_ID());
// Parameter
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null && para[i].getParameter_To() == null)
;
else if (name.equals("Date"))
{
p_Date = (Timestamp)para[i].getParameter();
}
else if (name.equals("AD_Org_ID"))
p_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("AD_Client_ID"))
p_AD_Client_ID = para[i].getParameterAsInt();
else if (name.equals("C_AcctSchema_ID"))
p_C_AcctSchema_ID = para[i].getParameterAsInt();
else if (name.equals("M_Product_Category_ID"))
p_M_Product_Category_ID = para[i].getParameterAsInt();
else
log.log(Level.SEVERE, "Unknown Parameter: " + name);
}
log.fine(sb.toString());
}
#Override
protected String doIt() throws Exception {
createDetailLines();
int AD_PrintFormat_ID = DB.getSQLValue(get_TrxName(), "Select AD_PrintFormat_ID from AD_PrintFormat Where name = 'Stock_Ageing'");
if (AD_PrintFormat_ID > 0) {
if (Ini.isClient())
getProcessInfo().setTransientObject (MPrintFormat.get (getCtx(), AD_PrintFormat_ID, false));
else
getProcessInfo().setSerializableObject(MPrintFormat.get (getCtx(), AD_PrintFormat_ID, false));
}
if (log.isLoggable(Level.FINE)) log.fine((System.currentTimeMillis() - m_start) + " ms");
return "";
}
private void createDetailLines() {
StringBuffer sb = new StringBuffer ("INSERT INTO T_ReportStockAgeing "
+ "(AD_PInstance_ID, AD_Client_ID, AD_Org_ID, ProductCode, Description, CurrentCost,"
+ " Qty1, Qty2, Qty3, Qty4, OnHand,"
+ " Value1, Valu2, Value3 ,Value4) ");
sb.append("SELECT ").append(getAD_PInstance_ID()).append(", ").append(Env.getAD_Client_ID(getCtx())).append(", ").append(Env.getAD_Org_ID(getCtx())).append(", ")
.append( "ProductCode, Description, Case OnHand WHEN 0 THEN 0 ELSE CurrentCost*OnHand END AS CurrentCost,"
+ "Qty1, Qty2, Qty3, Qty4, OnHand,"
+ "CASE OnHand WHEN 0 THEN 0 ELSE round((CurrentCost) * Qty1,2) END as Value1, "
+ "CASE OnHand WHEN 0 THEN 0 ELSE round((CurrentCost) * Qty2,2) END as Valu2, "
+ "CASE OnHand WHEN 0 THEN 0 ELSE round((CurrentCost) * Qty3,2) END as Value3, "
+ "CASE OnHand WHEN 0 THEN 0 ELSE round((CurrentCost) * Qty4,2) END as Value4 "
+ "FROM ( "
+ "SELECT "
+ "prod.value as ProductCode, "
+ "prod.description as Description, "
+ "M_Product_Category_ID, "
+ "(SELECT COALESCE (max(c.CurrentCostPrice),0) FROM M_Cost c WHERE c.AD_Org_ID =" +p_AD_Org_ID +" AND c.C_AcctSchema_ID= "+p_C_AcctSchema_ID+" AND prod.M_Product_ID = c.M_Product_ID AND prod.ProductType !='A' ) as CurrentCost, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.DateMaterialPolicy >= ( ("+p_Date+"::date) - interval '3 month' ) "
+ "AND st.DateMaterialPolicy <= ("+p_Date+"::date) "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A' "
+ ") as Qty1, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.DateMaterialPolicy >= ("+p_Date+"::date- interval '6 month' ) "
+ "AND st.DateMaterialPolicy <= ("+p_Date+"::date - interval '3 month') "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A') "
+ "as Qty2, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.DateMaterialPolicy >= ("+p_Date+"::date - interval '12 month' ) "
+ "AND st.DateMaterialPolicy <= ("+p_Date+"::date- interval '6 month') "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A' "
+ ") as Qty3, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.DateMaterialPolicy < ("+p_Date+"::date- interval '12 month') "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A' "
+ ") as Qty4, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A' "
+ ") as OnHand "
+ "FROM M_Product prod "
+ "LEFT JOIN AD_Org org ON org.AD_Org_ID = "+p_AD_Org_ID+" "
+ "LEFT JOIN M_Product_Category prodcat ON prodcat.M_Product_Category_ID = "+p_M_Product_Category_ID+" AND prodcat.AD_Client_ID = "+p_AD_Client_ID+" "
+ "WHERE prod.M_Product_Category_ID = "+ p_M_Product_Category_ID+" AND prod.ProductType !='A' "
+ ")temp ");
sb.append(" ) as temp ");
int no = DB.executeUpdate(sb.toString(), get_TrxName());
log.fine("#" + no);
log.finest(sb.toString());
}
}
I tried to integrate your class example for testing in iDempiere, but as GhostCat pointed, it's better if you create a minimal reproducible example, and also very important, please post also the error that is being thrown by the system, in UI and/or in console log.
The class doesn't have some imports, all the variables are not used, and the private method createDetailLines is never called, I assume the error you're mentioning is in that method, but there is no way to know if is not called.
Now, reviewing the SQL, there are two things to notice:
1 - it's not formatted for java, you use "AND c.C_AcctSchema_ID= $P{C_AcctSchema_ID}" and that's not the way as java manage variables, that sounds like jasper report syntax instead of java. For JDBC you must use ? as a replacement for binding variables
2 - iDempiere is multi-database, the way how the system is designed is to write oracle compatible SQL syntax, and there is a translation layer that converts the oracle statement ot postgresql syntax. So, it's better to avoid using postgresql specific syntax like "::date" or interval '3 month' - it could work, but it can also have problems with the convert layer. If you want to use specific postgresql syntax and avoid the convert layer being confused you can surround the postgresql specific syntax with NATIVE_PostgreSQL_KEYWORK - please don't blame me about the error in this constant :-)
I have written a java code which will fetch the data from the table and show the output. This is basically a script that I want to run through Nashorn.
Below is the code I'm trying
public static void main(String args[]) throws ScriptException{
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
String script3 = "count = 0; "
+ "keyList = new java.util.ArrayList; "
+ "valueList = new java.util.ArrayList;"
+ "keyList.add('username'); "
+ "keyList.add('password'); "
+ "valueList.add('admin'); "
+ "valueList.add('admin');"
+ "java.lang.System.out.println('keyList :: ' + keyList); "
+ "java.lang.System.out.println('KeyValue :: ' + valueList);"
+ "sql = \" select * from credentials where 'isActive'='1'\";"
+ "java.lang.System.out.println('keyList.size() :: ' + keyList.size());"
+ "for (i = 0; i < keyList.size(); i++){"
+ " sql += and \\' + keyList.get(i) + \\' = \\' + valueList.get(i) + \\';}"
+ "java.lang.System.out.println('Search SQL : ' + sql); "
+ "con = GetConnected.connectToDatabase('my_db');"
+ "ps = con.prepareStatement(sql); "
+ "ps.setString(1, \"1\");"
+ "rs = ps.executeQuery(); "
+ "if (rs.isBeforeFirst()) {"
+ " count=1; "
+ " java.lang.System.out.println('Data is present in database'); "
+ "}"
+ "else "
+ " java.lang.System.out.println('Data is not present in database'); "
+ " rs.close(); " + " st.close(); " + " con.close(); ";
engine.eval(script3);
}
The error I'm getting is
Exception in thread "main" javax.script.ScriptException: <eval>:1:904 Missing close quote
count = 0; keyList = new java.util.ArrayList; valueList = new java.util.ArrayList;keyList.add('username'); keyList.add('password'); valueList.add('admin'); valueList.add('admin');java.lang.System.out.println('keyList :: ' + keyList); java.lang.System.out.println('KeyValue :: ' + valueList);sql = " select * from credentials where 'isActive'='1'";java.lang.System.out.println('keyList.size() :: ' + keyList.size());for (i = 0; i < keyList.size(); i++){ sql += and \' + keyList.get(i) + \' = \' + valueList.get(i) + \';}java.lang.System.out.println('Search SQL : ' + sql); con = GetConnected.connectToDatabase('my_db');ps = con.prepareStatement(sql); ps.setString(1, "1");rs = ps.executeQuery(); if (rs.isBeforeFirst()) { count=1; java.lang.System.out.println('Data is present in database'); }else java.lang.System.out.println('Data is not present in database'); rs.close(); st.close(); con.close();
^ in <eval> at line number 1 at column number 904
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:534)
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:521)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at com.engine.nashorn.Test.main(Test.java:87)
Caused by: jdk.nashorn.internal.runtime.ParserException: <eval>:1:904 Missing close quote
count = 0; keyList = new java.util.ArrayList; valueList = new java.util.ArrayList;keyList.add('username'); keyList.add('password'); valueList.add('admin'); valueList.add('admin');java.lang.System.out.println('keyList :: ' + keyList); java.lang.System.out.println('KeyValue :: ' + valueList);sql = " select * from credentials where 'isActive'='1'";java.lang.System.out.println('keyList.size() :: ' + keyList.size());for (i = 0; i < keyList.size(); i++){ sql += and \' + keyList.get(i) + \' = \' + valueList.get(i) + \';}java.lang.System.out.println('Search SQL : ' + sql); con = GetConnected.connectToDatabase('my_db');ps = con.prepareStatement(sql); ps.setString(1, "1");rs = ps.executeQuery(); if (rs.isBeforeFirst()) { count=1; java.lang.System.out.println('Data is present in database'); }else java.lang.System.out.println('Data is not present in database'); rs.close(); st.close(); con.close();
^
at jdk.nashorn.internal.parser.Lexer.error(Lexer.java:1706)
at jdk.nashorn.internal.parser.Lexer.scanString(Lexer.java:988)
at jdk.nashorn.internal.parser.Lexer.lexify(Lexer.java:1615)
at jdk.nashorn.internal.parser.AbstractParser.getToken(AbstractParser.java:132)
at jdk.nashorn.internal.parser.AbstractParser.nextToken(AbstractParser.java:211)
at jdk.nashorn.internal.parser.AbstractParser.nextOrEOL(AbstractParser.java:170)
at jdk.nashorn.internal.parser.AbstractParser.next(AbstractParser.java:157)
at jdk.nashorn.internal.parser.Parser.parse(Parser.java:281)
at jdk.nashorn.internal.parser.Parser.parse(Parser.java:249)
at jdk.nashorn.internal.runtime.Context.compile(Context.java:1286)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1253)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:625)
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:532)
... 5 more
I think the place where the keyList and valueList value added to sql query it is giving problem.
sql += and \\' + keyList.get(i) + \\' = \\' + valueList.get(i) + \\';}"
that + will keep on adding until end of the script.
I get error ERROR: syntax error at or near "("
String deleteSQL = "DELETE FROM customer" +
"WHERE (fname = 'Fred' AND lname = 'Flintstone')" +
"OR (fname = 'Barney' AND lname = 'Rubble')";
System.out.println("Records deleted: "
+ stmt.executeUpdate(deleteSQL));
String deleteSQL = "DELETE FROM customer " +
"WHERE (fname = 'Fred' AND lname = 'Flintstone') " +
"OR (fname = 'Barney' AND lname = 'Rubble') ";
System.out.println("Records deleted: "
+ stmt.executeUpdate(deleteSQL));
The problem are the missing spaces while concatinating.
Imagine the following:
"word" + "word2"
this would result "wordword2"
so it should be
"word" + " " + "word2" or "word "+ "word2"
This code will retrive the data from database and it will match the column name from which data is retrieve with annotate field name . How do I cover this lines of code in unit testing using jmock ? Please help me to out of this problem.
ArrayList<String> criticalFields = getAllCriticalField("ORD", order
.getSrcSysId());
if (criticalFields != null && criticalFields.size() >= 1) {
String query = "select * from tvs.ORD where SRC_SYS_ID='"
+ order.getSrcSysId() + "' AND ORD_ID='"
+ order.getOrdId() + "'";
connection = vwsUtil.getConnection();
statement = connection.createStatement();
Field[] fields = Order.class.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if (field.isAnnotationPresent(TableColumnAnnotation.class)) {
TableColumnAnnotation column = field
.getAnnotation(TableColumnAnnotation.class);
if (criticalFields.contains(column.columnName())) {
if (column.columnName().equalsIgnoreCase(
"EST_RTS_DT")
|| column.columnName().equalsIgnoreCase(
"ACT_RTS_DT")
|| column.columnName().equalsIgnoreCase(
"CMIT_SHP_DT")
|| column.columnName().equalsIgnoreCase(
"ACT_FST_SHP_DT")
|| column.columnName().equalsIgnoreCase(
"ACT_FNL_SHP_DT")
|| column.columnName().equalsIgnoreCase(
"ORD_CANC_DT")
|| column.columnName().equalsIgnoreCase(
"SHP_BEF_DT")
|| column.columnName().equalsIgnoreCase(
"SHP_AFT_DT")) {
if (field.get(order) == null
|| field.get(order).toString()
.isEmpty()) {
query = query + " AND "
+ column.columnName() + " IS NULL ";
} else {
Calendar cal = (Calendar) field.get(order);
java.util.Date dt = cal.getTime();
SimpleDateFormat fmt = new SimpleDateFormat(
"dd-MM-yy");
String sqlDate = fmt.format(dt);
/*query = query + " AND "
+ column.columnName() + "='"
+ sqlDate + "'";*/
query = query + " AND "
+ column.columnName() + "=to_date('"
+ sqlDate + "','DD-MM-YY')";
}
} else if (column.columnName().equalsIgnoreCase(
"ORD_TS")
|| column.columnName().equalsIgnoreCase(
"ACK_TS")) {
if (field.get(order) == null
|| field.get(order).toString()
.isEmpty()) {
query = query + " AND "
+ column.columnName() + " IS NULL ";
} else {
Calendar cal = (Calendar) field.get(order);
java.util.Date dt = cal.getTime();
SimpleDateFormat fmt = new SimpleDateFormat(
"dd-MM-yy HH:mm:ss.SSSSSSSSS");
String sqlDate = fmt.format(dt);
query = query + " AND "
+ column.columnName() + "='"
+ sqlDate + "'";
/*query = query + " AND "
+ column.columnName() + "=to_date('"
+ sqlDate + "','DD-MM-YY HH:mm:ss.SSSSSSSSS')";*/
}
} else if (column.columnName().equalsIgnoreCase(
"DLR_MNG_TRNSP_IND")) {
if (field.get(order) == null
|| field.get(order).toString()
.isEmpty()) {
query = query + " AND "
+ column.columnName() + " IS NULL ";
} else {
query = query + " AND "
+ column.columnName() + "="
+ field.get(order).toString();
}
} else {
if (field.get(order) == null
|| field.get(order).toString()
.isEmpty()) {
query = query + " AND "
+ column.columnName() + " IS NULL ";
} else {
query = query + " AND "
+ column.columnName() + "='"
+ field.get(order).toString() + "'";
}
}
}
}
} //System.out.println("Order Query = "+query);
resultSet = statement.executeQuery(query);
if (!resultSet.next()) {System.out.println("Flag true in Order ");
criticalFieldFlag = true;
}
}
Not sure specifically what problem you are having - but this code is going to be hard to understand and hard to unit test in its current form.
Your life is going to be a lot easy if you refactor this beast into distinct responsibilities.
The bulk of the code looks to be generating sql strings - that's one coarse responsibility that ought to be easy to test independently once it's been pulled out.
Once the sql generation is pulled out, testing its interaction with the database will be much easier.
Of course, to refactor safely you need tests.
The current structure of the code makes unit tests difficult to write. Before you start I'd therefore suggest you put a lot of integration test coverage in place - i.e tests that exercise this code and hit the database.
I have the following fragment of code:
public static void main(String[] args) throws SQLException {
Connection c = getConnection();
long time = System.currentTimeMillis();
PreparedStatement ps = c.prepareStatement(sqlQuery);
int index = 1;
for (String param: parameters) {
if (isInt(param)) {
//ps.setInt(index++, Integer.parseInt(param));
ps.setObject(index++, Integer.parseInt(param), java.sql.Types.NUMERIC , 0);
} else {
ps.setString(index++, param);
}
}
displayResult(ps.executeQuery());
System.out.println("It took " + (System.currentTimeMillis()-time) + ".");
time = System.currentTimeMillis();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery(expandParametersInStatement(sqlQuery, parameters));
displayResult(rs);
System.out.println("It took " + (System.currentTimeMillis()-time) + ".");
}
The query executed with a PreparedStatement is slower by a factor of 4000. Compared to the Statement approach. They give the same result and the order of execution makes no huge difference.
Using the setObject() instead of setInt() makes the PreparedStatement as fast as the Statement.
What is the difference? The cast in the Database cannot be that expensive? The data type in the database is a NUMBER(10). I guess it is a matter of the indeces which are used. However, I cannot replicate this in the SQL Developer with CAST(x AS INTEGER)?
Thanks.
The statement is:
private static String sqlQuery = "SELECT sum(value) " +
"FROM a monat, " +
" n jahr, " +
" kunde kunde " +
"WHERE monat.kunde_nr IN " +
" (SELECT DISTINCT kunde.kunde_nr " +
" FROM MASKE_4_KUNDEN kunde " +
" WHERE kunde.firma_nr = ? " +
" AND kunde.verkaufsbereich_nr = ? " +
" AND kunde.vertriebsbereich_nr BETWEEN (CASE WHEN ? <> -1 THEN ? ELSE -9999999999 END) AND (CASE WHEN ? <> -1 THEN ? ELSE 9999999999 END) " +
" AND kunde.vertreter_nr BETWEEN (CASE WHEN ? <> -1 THEN ? ELSE -9999999999 END) AND (CASE WHEN ? <> -1 THEN ? ELSE 9999999999 END)" +
" AND kunde.konzern_nr BETWEEN (CASE WHEN ? <> -1 THEN ? ELSE -9999999999 END) AND (CASE WHEN ? <> -1 THEN ? ELSE 9999999999 END) " +
" AND kunde.geschaeftsjahr = ? " +
" AND kunde.kunde_nr BETWEEN (CASE WHEN ? <> -1 THEN ? ELSE -9999999999 END) AND (CASE WHEN ? <> -1 THEN ? ELSE 9999999999 END))" +
" AND monat.firma_nr = ? " +
" AND monat.verkaufsbereich_nr = ? " +
" AND monat.jahr_nr = ? " +
" AND jahr.kunde_nr = monat.kunde_nr " +
" AND jahr.firma_nr = monat.firma_nr " +
" AND jahr.jahr_nr = monat.jahr_nr " +
" AND jahr.verkaufsbereich_nr = monat.verkaufsbereich_nr " +
" AND kunde.kunde_nr = monat.kunde_nr " +
" AND kunde.firma_nr = monat.firma_nr";
setInt() method receives int as a second parameter (not Integer). now, I know that auto-boxing should work but apparently it doesn't always work: http://www.coderanch.com/t/550628/JDBC/java/setInt-String-int-Lost
My guess is that it didn't work in older versions of JDBC and it works in newer versions but is still buggy...
I would try using Integer.intValue() and see if it works any better!
If anyone has more input in regards - I'd love to hear it!
We observed the same behavior also with a prepared statement having just setString() statements over an Oracle Database 10.2.0.4.0.
The problem has been completely solved updating the jdbc driver from 10.2.0.3.0 to 10.2.0.4.0