[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

selectAndOrderPs.setString(1, visitId)

Posted on 2004-10-15
5
Medium Priority
?
294 Views
Last Modified: 2012-06-21
   
Hi!

Can anybody tell me what selectAndOrderPs.setString(1, visitId) does in detail?
++++++++++++++

private String selectTitlesAndOrder="select test.assess_test_id as id, type.test_type_title as title"+ " FROM Assess_Tests test, Assess_test_types type" +" WHERE visit_id=? AND" + " test.assess_test_type_id=type.assess_test_type_id" + " ORDER BY ?";


public LinkedHashMap selectTitlesAndOrder(String visitId, String orderParam)
       throws SQLException {
            log.debug("start");

            LinkedHashMap testMap = new LinkedHashMap();
            
            selectAndOrderPs = db.prepareStatement(selectTitlesAndOrder);
            selectAndOrderPs.setString(1, visitId);
            selectAndOrderPs.setString(2,orderParam);

            ResultSet rs = selectAndOrderPs.executeQuery();
      
            while(rs.next()) {
                  testMap.put(rs.getString("id"), rs.getString("title"));
            }

            selectAndOrderPs.close();
            
            return testMap;
    }
++++++
thanks,
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 20

Accepted Solution

by:
Venabili earned 172 total points
ID: 12322528
Hi dkim18,
Sets the value written in visitId at the place of the first ?. It also escapes the value if needed....

Venabili
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 164 total points
ID: 12322538
It's a wrapper around a query that parameterizes a query based on its id and sort order. A Map is built such that the test assess id returned by the query is mapped to the titles of the tests
0
 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 164 total points
ID: 12323026
The setString(n, str) set the parameter at location n to the string str.  This assumes that the statement has been prepared with parameters and that the ? position is mapped to a string.  If not a SQLException will occur.

In your example the SQL statment has parameters on 'visit_id=?', and 'ORDER BY ?'.  The 1st is valid and is parameter one.  The second will not work.  The reason is that the database uses the parameterized SQL statment and generates its internal Query.  If the statement has been used before, the database may choose to cache the statement compilation and thus make your query faster.  You cannot set the parameter on ORDER BY because the database needs to know how to sort the results BEFORE it is executed.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question