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

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -