User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 374,011 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,783 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 591 | Replies: 2
Reply
Join Date: May 2008
Location: US
Posts: 1
Reputation: Hockey-nut is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Hockey-nut Hockey-nut is offline Offline
Newbie Poster

JSP-SQL Query to Access DB with Parameterized Query

  #1  
May 11th, 2008
I'm new to JSP and trying to do a parameterized query. I've been able to do single stream queries to existing tables without any problem. I'm trying to build a search mechanism to do selective reporting.

I've tried many hours to get the combination of different items to get by the ODBC SQL interface and have not been able to get the combination to work. Your advice/help would be greatly appreciated.

The following is the types of code being used. Html code setting up parameters being passed to .jsp page looks like this:

=====================================================
  1. <form id="inputForm" name="inputForm" onsubmit="return validateOnSubmit()" title="schoolsearch" method="post" action="sS1.jsp">
  2.  
  3. <h4>
  4. Select Degree Option
  5. </h4>
  6.  
  7. <input type="radio" value="A" name="degreeOption" />Associate
  8. <input type="radio" value="B" name="degreeOption" />Bachelor
  9. <input type="radio" value="M" name="degreeOption" />Masters
  10. <input type="radio" value="P" name="degreeOption" />Ph. D
  11. <input type="radio" value="T" name="degreeOption" />Training
  12. <input type="radio" value="C" name="degreeOption" />Certificate
  13.  
  14. <h4>
  15. Select Search option below:
  16. </h4>
  17. <input type="radio" value="1" name="Search" /> Program
  18. <input type="radio" value="2" name="Search" /> Institution
  19. <input type="radio" value="3" name="Search" /> PDF options
  20. <input type="radio" value="4" name="Search" /> Mail Report
  21. <input type="radio" value="5" name="Search" /> Request Other Information
  22.  
  23. <p> If you are looking for a <em>particular Program</em>, please type a search term below:
  24. <br />
  25. <input type='text' name='progName' id='progName' size='30' onchange='validateOther(this,'progName');'
  26. </p>
  27. <p> If you are looking for a <em>Institution</em>, please type a search term below:
  28. <br />
  29. <input type='text' name='instName' id='instName' size='30' onchange='validateOther(this,'instName');'
  30. </p>

=====================================================
The sS1.jsp page gets the the degreeOption and Search fields. The code within sS1.jsp
looks like this:

  1. input1=request.getParameter("degreeOption");
  2. input2=request.getParameter("Search");
  3. choice = Integer.parseInt(input2) ;
  4.  
  5. searchTerm=request.getParameter("progName");
  6. searchName=request.getParameter("instName");
  7.  
  8. switch (choice)
  9. {
  10. case 1:
  11. out.println("--> Program selection -- Case 1" ) ;
  12. sqlQuery = ("SELECT InstDegreeProgram.Program
  13. FROM InstDegreeProgram
  14. WHERE (((InstDegreeProgram.Program) Like " + "\"*\"" + input2 + "\"*\""))
  15. ORDER BY InstDegreeProgram.Program); ";
  16. break;
  17. case 2:
  18. out.println("-- Institution selection -- Case 2" ) ;
  19. sqlQuery = "Case 2 : " ;
  20. sqlQuery = ("SELECT InstDegreeProgram.Program
  21. FROM InstDegreeProgram
  22. WHERE (((InstDegreeProgram.Program) Like \"*\" "+ input2 + " \"*\"))
  23. ORDER BY InstDegreeProgram.Program)" ;
  24. break;
  25. }
  26.  
  27. java.sql.ResultSet rs = sqlQuery.executeQuery();

===================================
JSP -- Error report

String literal is not properly closed by a double-quote # 148
145:       {
146:         case 1:
147:            out.println("--> Program selection -- Case 1" ) ;
148:            sqlQuery = ("SELECT   InstDegreeProgram.Program
149:                         FROM     InstDegreeProgram
150:                         WHERE (((InstDegreeProgram.Program) Like " + "\"*\"" + input2 + "\"*\""))
151:                         ORDER BY InstDegreeProgram.Program); ";
==============================================

The microsoft query that works within the Access Database looks like this:

  1. SELECT InstDegreeProgram.Program
  2. FROM InstDegreeProgram
  3. WHERE (((InstDegreeProgram.Program) LIKE "*" & [What Program: ?] & "*"))
  4. ORDER BY InstDegreeProgram.Program;

Hope this helps to provide you with background information that I'm working with in the future.
Last edited by peter_budo : May 12th, 2008 at 8:21 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,588
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 187
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JSP-SQL Query to Access DB with Parameterized Query

  #2  
May 12th, 2008
don't use scriptlets, don't put business logic in JSP, don't use Access as a database, use code tags
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: May 2008
Posts: 2
Reputation: sinan.yk is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sinan.yk sinan.yk is offline Offline
Newbie Poster

Re: JSP-SQL Query to Access DB with Parameterized Query

  #3  
May 13th, 2008
hi, guy. i think same as jwenting. and your query string's errror is that you have to write your query as a string. your query string should be like that sqlquery=#
"SELECT InstDegreeProgram.Program
FROM InstDegreeProgram
WHERE (((InstDegreeProgram.Program) Like " + "\"*\"" + input2 + "\"*\""+"))"+"ORDER BY InstDegreeProgram.Program";
you must close string literals. see you..
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 10:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC