java - I want to insert a special character of SQL in JDBC -
i want translate access sql query java jdbc
select * books lcase(title) lcase('*jdbc*') , lcase(title) lcase('*programming*')
i use preparedstatement this
string sql1="select * books lcase(title) lcase(%?%) , lcase(title) lcase(%?%)"; preparedstatement ps1=con.preparestatement(sql1); ps1.setstring(1, "jdbc"); ps1.setstring(2, "programming"); resultset rs1=ps1.executequery();
but syntax error
if want insert %
value used lcase
, have 2 choices:
- add
%
s in code, or - use concatenation in query.
the first approach this:
string sql1="select * books lcase(title) lcase(?) , lcase(title) lcase(?)"; preparedstatement ps1=con.preparestatement(sql1); ps1.setstring(1, "%jdbc%"); ps1.setstring(2, "%programming%");
the second approach this:
string sql1="select * books lcase(title) lcase('%' & ? & '%') , lcase(title) lcase('%' & ? & '%')";
Comments
Post a Comment