Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finding a missing number

 
vinu pillai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i find a missing number stored in database say an oracle database...Like for e.g there are 1 - 10 numbers in database...and the numbers 5 and 7 are missing in...so..! i want to print these two missing numbers in front end ....The code which i coded is ..
import java.sql.*;
class testNum {
public static void main(String args[]) throws Exception {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Category_Trans";
String username = "vinu";
String password = "vinu";
Connection connection = null;
ResultSet rset = null;
int num = 0;
int i;
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement();
rset = statement.executeQuery("select * from number_test");
if(rset != null) {
while(rset.next()) {
num = rset.getInt(1);
//System.out.println(num);
}
}
for(i=1;i<=num;i++) {
System.out.println(i);
/*if(i!=num)
System.out.println("1.." +num);
else
System.out.println("2.." +i);*/
}
System.out.println();
}
}
but it's not printing what i wanted..
plz if there is any solution then help me out...

thanks
Vinu
 
vivek makode
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
take the result set data in an integer array and not a single number.
u have taken int num.
take int num[];
 
vinu pillai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks buddy...

Originally posted by vivek makode:
take the result set data in an integer array and not a single number.
u have taken int num.
take int num[];

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic