Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Getting number of "?" out of the dql query

Posted on 2006-04-30
Medium Priority
Last Modified: 2008-03-17
I have a text box, in which user's come and type in the dql statement like “select * from dm_document where owner_name = ?  and object_name=?". I need to get the count of all the "?" marks in the query. Like in this case it was 2 questions marks. How can i accomplish this task in my java class.
Question by:janjuama84
  • 2
LVL 17

Accepted Solution

BogoJoker earned 1500 total points
ID: 16574507
If they just type in a string, you can keep a running tally and keep searching:

String dql = "select * from dm_document where owner_name = ?  and object_name=?";
int count = 0;
int pos = dql.indexOf("?");
while (pos != -1)
  pos = dql.indexOf("?", pos+1);
// after the loop, count has the number of question marks.

LVL 17

Expert Comment

ID: 16574519
A little more compact, into a for loop:

String dql = "select * from dm_document where owner_name = ???  and object_name=?";
int count = 0;
for(int pos = dql.indexOf("?"); pos != -1; pos = dql.indexOf("?", pos+1))

Joe P
LVL 92

Expert Comment

ID: 16574563
PreparedStatement ps = conn.prepareStatement(dql);
int count = ps.getParameterMetaData().getParameterCount();

LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16574875
check out.

yes getting it from the getParameterMetaData is a good way.

Thank You.

Featured Post

Industry Leaders: 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

577 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