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

thank you Jamie Robertson &Lewis Chao my code is:

 
alex han
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
connectionPool is a custom class
in DAO:
public int INSERT(TInfo tInfo,int sId)throws Exception
{
Connection connection = null;
PreparedStatement stmt = null;
PreparedStatement insert_stmt = null;
ResultSet results = null;
int j=0;
try
{
connection = connectionPool.getConnectionNoWait();
stmt = connection.prepareStatement("select MAX(TCHR_ID) from TCHR_INFO where TCHR_ID LIKE '"+sId+"%'");
results = stmt.executeQuery();
while(results.next())
{
j=results.getInt(1)+1;
System.out.println("results:"+results.getInt(1));
}
System.out.println("j:"+j);
......
i make sure that no record in table TCHR_INFO(in oracle81),but print results:0 and j:1
Does it cause by i use MAX()?
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a result and the result is null ( in my DB's case anyways ). Different db's react differently but you can almost assure yourself that when you issue a count, max, min or any other single row function you can expect a result back ( even if the table is empty ).
the reason you are getting zero for your results is that the getInt() method returns either an integer OR a zero if the result was null. If you want to check if the previous value really a zero or it it was null then use wasNull() method:

don't know what exactly you are trying to do, this will tell you if the max value is actually zero or null.
Jamie
Jamie
 
Chetan M
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi hit,
When u use aggregate functions like max(),min(),count() etc..u'll get a count or rather an integer in the result set.. since in ur case the query will return the count of records i got by executing the query.. which is 0 since , there r no records present. So a result is produced with all field values '0'...
Thats y u got result of getInt(1) as 0.
Chetan
 
alex han
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very helpful, thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic