spassing multiple params in select query

39 Views Asked by At

I am working with query "select * from account in (?)"

I using preparedstatement+select query+ in clause. I want to provide multiple accounts of String type. I have tried it by using Stringbuilder but it did not worked.

    Stringbuilder inclause = new Stringbuilder();
    inclause.append("123");
    inclause.append("345")
    
    Statement.setString(inclause.toString())

This code is not working for me because this is forming query like:

select * from account in ('123, 345')

and this is not correct query as I require like:

select * from account in ('123', '345')

Could you please help me in achieving this?

1

There are 1 best solutions below

1
Dinesh Ganesan On
Stringbuilder inclause = new Stringbuilder();
inclause.append("'123'");
inclause.append(",");
inclause.append("'345'");
Statement.setString(inclause.toString());

Add single quotes in string and also add append ","