Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Helper tool to Build SQL in JSP??

 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am relatively new to JDBC.
I have a JSP where user enters seach criteria. I called javabean thru JSP to connect and execute the SQL.
But it is getting more and more difficult to generate the query statement based on the criteria entered by the user on the JSP(html) page.

For ex: There are 6 fields user can enter on the page. I am building the query using complicated logic as shown below.
Question:
Is there any (freeware) tool which can help building SQL queries?



String REF_NO = request.getParameter("REFNO");
String TEMAIL = request.getParameter("TEMAIL");
String FORM = request.getParameter("FORM");
String CRDT = request.getParameter("CRDT");
String ToCRDT = request.getParameter("ToCRDT");

String query1 = "";
String query2 = "";
String query3 = "";
String query4 = "";
int count = 0;

//ResultSet rs = new ResultSet();

String Query = "";

if ( !(REF_NO == null) && !(REF_NO.equals("")))

query1 = "REF_NO like '%" + REF_NO + "%'";

if ( !(TEMAIL == null) && !(TEMAIL.equals("")))
query2 = "TEMAIL like '%" + TEMAIL + "%'";

if ( !(FORM == null) && !(FORM.equals("")))
query3 = "FORM like '%" + FORM + "%'";

if (!(CRDT.equals("")))
String Dt1 = "TO_DATE('" + CRDT + "', 'mm/dd/yyyy')";

if (!(ToCRDT.equals("")))
String Dt2 = "TO_DATE('" + ToCRDT + "', 'mm/dd/yyyy')";

if (!(query1.equals("")))
Query = query1;

if (!(query2.equals(""))) {
if (!Query.equals("")) {
Query = Query + " and " + query2; } else
Query = query2;
}

if (!(query3.equals(""))) {
if (!Query.equals("")) {
Query = Query + " and " + query3; } else
Query = query3;
}

if (!(Query.equals("") {

//Query = Query + " CRDT between TO_DATE('06/01/2004', 'mm/dd/yyyy') and TO_DATE('06/30/2004', 'mm/dd/yyyy')";
if (Query.equals(""))
Query = "empty";

ELOG.connect();
ResultSet rs = ELOG.searchLog(Query);






Thanks,
Manoj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic