why my resultset return this???
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   hit_demo
Posted On:   Monday, December 23, 2002 02:00 AM

my code is: 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(   More>>

my code is:
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()?
someone told me that if there are no record in table ,results.next() return false,so j should equals 0 and System.out.println should not execute
but i find that even there are no record in table , j equals 1!
why?

help me!!

   <<Less

Re: why my resultset return this???

Posted By:   Krishan_Gupta  
Posted On:   Monday, December 23, 2002 09:40 PM

Hi Demo


When you run query like "select max(column)....or select count(* or some column)...", rs.next() would be true even if is does not contain any value!! So you need to check for null or 0 depending upon how you are retrieving the value from resultset. This is in accordance with what you get when you run the query simply from your sql prompt.



Hope it helps!!



K Gupta
About | Sitemap | Contact