Solved

selectAndOrderPs.setString(1, visitId)

Posted on 2004-10-15
5
286 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 43 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 41 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 41 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

729 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