1

I have to format a string such that it can be sent to the IN clause of SQL. String s = ('A','B').This string s shud be passed from java to sql.How can this be done

prasanna
  • 51
  • 2
  • 9

2 Answers2

2

I have come across this many times and to the best of my knowledge each element in the set needs to be a separate parameter:

String sql = "select * from customer where city in (?, ?, ?)";
PrepareStatement p = ..;
p.setString("Mumbai");
p.setString("Pune");
p.setString("Bangalore");
...
Miserable Variable
  • 28,432
  • 15
  • 72
  • 133
-1

Simply create the SQL statement and append the string to it

String sql = "SELECT a FROM table WHERE a IN "+s;

Now you can create a SQL Statement from this string. A better way may be to use prepared statements...

hage
  • 5,966
  • 3
  • 32
  • 42