Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple integer comparison

Status
Not open for further replies.

volcano

Programmer
Aug 29, 2000
136
HK
Hi, I don't know why my following simple Java codes can't be complied. Would you experienced programmers teach me? Thanks

---------------------

ResultSet result = sql.executeQuery("select (to_char(sysdate,'hh24')*60 to_char(sysdate,'mi')) - (to_char(ANOTHERTIME,'hh24')*60 + to_char(ANOTHERTIME,'mi')) as
diff from TABLE ");

while ( result.next() ) {
String diff = result.getString("diff");
int diff2 = Integer.parseInt(diff);
}
conn.close();

if ( diff2 > 60 ) {
System.out.println("Over an hour");
}

--------

Test.java:29: cannot resolve symbol
symbol : variable diff2
location: class Test
if ( diff2 > 60 ) {
^
1 error
 
Your diff2 variable is not in scope of the 'if' statement. Try this :

Code:
ResultSet result = sql.executeQuery("select (to_char(sysdate,'hh24')*60 to_char(sysdate,'mi')) - (to_char(ANOTHERTIME,'hh24')*60 + to_char(ANOTHERTIME,'mi')) as
diff from TABLE ");

int diff2 = 0;
while ( result.next() ) {
String diff = result.getString("diff");
 diff2 = Integer.parseInt(diff);
}
conn.close();

if ( diff2 > 60 ) {
System.out.println("Over an hour"); 
}

--------------------------------------------------
Free Database Connection Pooling Software
 
Thank you for your help! I am so careless
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top