?
Solved

selectAndOrderPs.setString(1, visitId)

Posted on 2004-10-15
5
Medium Priority
?
290 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 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