Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic