Solved

selectAndOrderPs.setString(1, visitId)

Posted on 2004-10-15
5
280 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

733 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