This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I need help to solve this problem, i want to search database based on 4 inputs, 2- form inputs and 2- selectboxes and one submit button in a JSP page....I am stuck here....please can anybody plzzz help me out :) , Just give me some idea or simple sample code would be great. This is very urgent for me.
I tried this but not able to get it, I need to retrieve data from db based on 2 form inputs and 2 selectboxes with one submit button... here is my code
This code is not working...when i enter the values and click submit ...it gives me "sorry couldn't find data"...Please anyone lookinto my code and tell me ..where the prob is...I am really stuck. I even tried with servlet...but same output(Sorry couldn't find data). Please help me.
1 - Don't use scriptlet code in JSP. Java code belongs in servlets/beans.
2 - The JDBC-ODBC bridge driver is . I suggest getting a real database, with a supported JDBC driver (MySQL, Oracle, MSSql...)
3 - When constructing sql statements with strings, you leave yourself open to sql injection attack. Instead your sql should use prepared statements to pass in the users values.
Specific to this code.
- You need to match up the names of your controls with the request parameters you are looking for.
For instance you have:
CABINET/EXCHANGE/TER <> Cabinet
The control "name" and the request parameter being retrieved must match.
I would suggest renaming the input components on AutoAssign.jsp to match what you have in the getParameter() calls in retrieve.jsp.
Suggested debugging steps
- print out the values of the search fields on your results page so that you can see they came through correctly.
- print out the sql generated to execute. Try running it on your database, and see what you get. Fiddle with it until you get sql that works, and then try translating the changes back to your code.
Things to think about
- are all your search parameters necessarily used to run the query? Particularly the remarks column will restrict the results too much I would think.
- consider writing the query logic into a java class. This code sample is based on patterns from 10 years ago. We've come a long way since then.
Joined: Oct 27, 2010
Thanks for the quick reply...will try this and get back to you.