Hi Can any one help me I am having a problem with this code...
Stmt=SELECT VERSION, PROGRUNLOC, NAMECOUNT, PROGLEN, PROGTXT, TO_CHAR(LASTUPDDTTM,'YYYY-MM-DD-HH24.MI.SS."000000"'), LASTUPDOPRID, PROGSEQ FROM PSPCMPROG WHERE OBJECTID1 = *:1* AND OBJECTVALUE1 = *:2* AND OBJECTID2 = *:3* AND OBJECTVALUE2 = *:4* AND OBJECTID3 = *:5* AND OBJECTVALUE3 = *:6* AND OBJECTID4 = *:7* AND OBJECTVALUE4 = *:8* AND OBJECTID5 = *:9* AND OBJECTVALUE5 = *:10* AND OBJECTID6 = *:11* AND OBJECTVALUE6 = *:12* AND OBJECTID7 = *:13* AND OBJECTVALUE7 = *:14* ORDER BY PROGSEQ
Bind-1 type=8 length=4 value=1
Bind-2 type=2 length=15 value=AB_GENLDED_SRCH
Bind-3 type=8 length=4 value=2
Bind-4 type=2 length=8 value=ORDER_BY
Bind-5 type=8 length=4 value=12
Bind-6 type=2 length=10 value=SearchSave
Bind-7 type=8 length=4 value=0
Bind-8 type=2 length=1 value=
Bind-9 type=8 length=4 value=0
Bind-10 type=2 length=1 value=
Bind-11 type=8 length=4 value=0
Bind-12 type=2 length=1 value=
Bind-13type=8 length=4 value=0
Bind-14 type=2 length=1 value=
In the above sql statement the bold ones are bind variables..and their associated values are present in italicised manner.In the sql statement the :1 must be replaced by 1 and :2 must be replaced by AB_GENLDED_SRCH.
I wrote the following code
if (strLine.contains(":")) {
query = strLine;
for (int i = 0; i < query.length(); i++) {
if (query.charAt(i) == ':') {
count++;
}
}
} else if (strLine.contains("value=")) {
String[] store = strLine.split("value=");
if (store[1].contains("&")) {
store[1] = store[1].replaceAll("&", "");
}
argList.add(s.concat(store[1].concat("'")));
if (argList.size() == count) {
for (int j = 0; j < argList.size(); j++) {
*query =*
*query.replace(*
*":" + (j + 1),*
*argList.get(j).toString());*
}
argList.removeAll(argList);
count = 0;
String query1 = query.replaceAll("'", "''");
pw.println("EXTRACT_SQL.Return_SQLTime('" + query1 + "');");
}
}
on executing i am getting this output
SELECT VERSION, PROGRUNLOC, NAMECOUNT, PROGLEN, PROGTXT, TO_CHAR(LASTUPDDTTM,''YYYY-MM-DD-HH24.MI.SS."000000"''), LASTUPDOPRID, PROGSEQ FROM PSPCMPROG WHERE OBJECTID1 = ''1'' AND OBJECTVALUE1 = ''AB_GENLDED_SRCH'' AND OBJECTID2 = ''2'' AND OBJECTVALUE2 = ''ORDER_BY'' AND OBJECTID3 = ''12'' AND OBJECTVALUE3 = ''SearchSave'' AND OBJECTID4 = ''0'' AND OBJECTVALUE4 = '' '' AND OBJECTID5 = ''0'' AND OBJECTVALUE5 = '*'1''0* AND OBJECTID6 = *''1''1* AND OBJECTVALUE6 = *''1''2* AND OBJECTID7 = *''1''3* AND OBJECTVALUE7 = *''1''4* ORDER BY PROGSEQ'
In the above the code is replacing bind variables perfectly till bind variable no..9 i.e.; OBJECTID5 ...from variable 10 onwards. ie., for :10 the code is replacing :1 with the value of variable 1..so it is showing "1"0 instead of the value at bind variable 10...
The problem is with replace statement in bold in the code..but I am not able to solve the problem can anyone help