I have a static query as Select * from Emp where Empid in (?) and I have that value of (?). I am not able to place that value. Please guide me. Let me know, I f anything else is required.
-
1Can you share your code?Mureinik– Mureinik2014-02-14 13:07:09 +00:00Commented Feb 14, 2014 at 13:07
-
1docs.oracle.com/javase/tutorial/jdbc/basics/prepared.htmlJB Nizet– JB Nizet2014-02-14 13:10:28 +00:00Commented Feb 14, 2014 at 13:10
-
Hi Mureinik, there is nothing to share the code. i have fetch the data from DB as well as from JSP. and unable to set that value. please suggest me, how can I do that ? And, thanks for correcting the question.Archit Mathur– Archit Mathur2014-02-14 13:10:29 +00:00Commented Feb 14, 2014 at 13:10
-
is it because the method is static and the variable you want to set is not static, so in the method it is not available (due to static/non static fields? or are you trying to set it and at the DB level the variable is null?Mark Giaconia– Mark Giaconia2014-02-14 13:11:35 +00:00Commented Feb 14, 2014 at 13:11
-
Thanks JB Nizet for the link. It really works....Archit Mathur– Archit Mathur2014-02-14 13:15:00 +00:00Commented Feb 14, 2014 at 13:15
Add a comment
|
1 Answer
Try this java code:
public boolean yourMethod(String yuorValue) {
String sql = "select * from user where fieldName = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, yuorValue);//fieldvalue(1), Your passing value
ResultSet rs = stmt.executeQuery();
return rs.next();
}