This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HELP -- Counting rows with oracle & jdbc

 
erin_az
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code snippet:
String queryJoinCount = "select count(contract_type_id) from clause_type_join where clause_id = ? and comment_id = ?";
PreparedStatement stmt = conn.prepareStatement(queryJoinCount);
stmt.setInt(1, clause.getId());
stmt.setInt(2, comment.getId());
ResultSet rs_count = stmt.executeQuery();
if(rs.next()){
//then some results were returned
int count = rs.getInt("count(contract_type_id)"); //problem here
}
I keep getting an sql exception on the line inside the if statement.
How do I refer to the column name that Oracle's count mechanism is returning?
thanks,
Erni
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you name the the count field like
select count(emp_id) emp_cnt from....
emp_cnt is now the field name
Dan
 
erin_az
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is helpful to know, thanks,
e.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!