This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes To Get the Number of Matches Found in the Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "To Get the Number of Matches Found in the Database" Watch "To Get the Number of Matches Found in the Database" New topic
Author

To Get the Number of Matches Found in the Database

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I am working a database search by supplying a 'memberName'. There is a field in the data table called 'message_receiver'. I want to count the number if the 'memberName' and the 'messag_receiver' is a match and return the number. How do I do it?
Mukesh Netedge
Greenhorn

Joined: Apr 17, 2004
Posts: 10
Hi JiaPei Jen ,
It seems you need count of the result set returns from the query according to the parameter passed.
Try the following query:
String query = "SELECT count(*****) as countNo FROM message_thread WHERE message_receiver = '" + memberName + "'";
or
String query = "SELECT count(*****) as countNo FROM message_thread WHERE message_receiver like '%" + memberName + "%'";
Then usinf your resultset retrieve the first element as
String noOfMembers=rs.getString("countNo")
Hope it will hepl you.
Mukesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To Get the Number of Matches Found in the Database