java - How to write variables inside Query language? -


example:

string s1; string q = "select * entrybytitle booktitle='"+s1+"'"; 

here in query statement why +s1+ used in syntax. s1 string, should '"s1"'. why '"+s1+"' written in project.

use preparedstatement , bind parameter. takes form

string q = "select * entrybytitle booktitle=?"; string booktitle = ""; connection conn = null; try {     try (preparedstatement ps = conn.preparestatement(q)) {         ps.setstring(1, booktitle);         try (resultset rs = ps.executequery()) {             while (rs.next()) {                 system.out.println(rs.getstring("booktitle"));             }         }     } } catch (exception e) {     e.printstacktrace(); } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -