1

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.

5
  • 1
    Can you share your code? Commented Feb 14, 2014 at 13:07
  • 1
    docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html Commented 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. Commented 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? Commented Feb 14, 2014 at 13:11
  • Thanks JB Nizet for the link. It really works.... Commented Feb 14, 2014 at 13:15

1 Answer 1

1

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(); 
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.