-1

I am passing argument in query using property files like indexid=a,b,c,d.Below is my code-

 PreparedStatement ps =conn.prepareStatement("Select * from indexcalc where DATE between ? and ? and "+"isd_index in ?");
            ps.setDate(1, d1);
            ps.setDate(2, d2);
            ps.setString(1, indexList);

Now problem is if I mark values in property file like 'a','b',query runs fine but i want passing argument like a,b.So what will be approach so that argument passed like a should be treated by query as 'a'.please suggest.

Yash Varshney
  • 365
  • 1
  • 5
  • 16

1 Answers1

0

for a simple and quick solution read the file in a String S then

String[] sArray= S.split(",");
//now sArray contains all the values
String indexList= null;
for(int i=0;t<sArray.length;i++){
 sArray[i]= "'"+sArray[i]+"'";
 indexList= indexList + sArray[i];
 }
 //with 'a' sArray

now simply pass this as argument in

PreparedStatement ps =conn.prepareStatement("Select * from indexcalc where DATE between ? and ? and "+"isd_index in ?");
        ps.setDate(1, d1);
        ps.setDate(2, d2);
        ps.setString(3, indexList);
Bhargav Modi
  • 2,605
  • 3
  • 29
  • 49