How to make use of string variables in a query in jsp

Multi tool use


How to make use of string variables in a query in jsp
I have 2 string variables name and password. Now I have to use these variables in a query in where condition. How should I do it.
Suppose I want to execute a query-
"SELECT * FROM students WHERE students.name=name and student.pass=password"
I'm not able to do it. What is the right syntax for this query statement?
1. don't put such code in JSPs. JSPs are view components, supposed to generate HTML from objects stored into request attributes, and nothing else. Learn about MVC, and put the data access code into Java classes. 2. Learn JDBC. Google for Java JDBC tutorial. Specifically, learn about prepared statements.
– JB Nizet
26 mins ago
@JBNizet, he may also learn hibernate too, depending on his needs and his environment...
– mr.mams
10 mins ago
@mr.mams the guy puts all its Java code in JSPs right now. Using Hibernate (or any other persistence technology) is premature. Start with the basics. Learn how to write Java classes first. Then learn the basics of persistence.
– JB Nizet
8 mins ago
1 Answer
1
PreparedStatement st=conn.prepareStatement("SELECT * FROM students WHERE students.name=? and student.pass=?");
st.setString(1, name);
st.setString(2, password);
ResultSet rs=st.executeQuery();
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
what you are using jdbc or hibernate framework for database connection.?
– Tejal
29 mins ago