Results 1 to 5 of 5
- 06-08-2009, 12:59 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 18
- Rep Power
- 0
Collecting ResultSet data and Comparing
Hi everyone,
I have problem with Collecting data from sql query into Array or ArrayList and comparing them with outside values.
here my problem is ArrayList gets only one data, when I sort them withJava Code:public void roomCheck()throws SQLException,ClassNotFoundException{ String roo = jTextField11.getText(); try { databaseConnection(); stm=con.createStatement(); rs=stm.executeQuery("select * from reservation"); int room = Integer.parseInt(roo); while(rs.next()){ ArrayList roomNumbers= new ArrayList(); roomNumbers.add(rs.getInt("odano")); Iterator it=roomNumbers.iterator(); while(it.hasNext()){ if(it.next().equals(room)){ JOptionPane.showMessageDialog(null,"Warning !!!! The room is full"); } else{ reservationAdd(); } } } } catch(SQLException e){ e.getCause(); } stm.close(); con.close(); }
System.out.println(it.next()) ;
I can see the datas without problem however when I compare them in if else condition, it compares only one data and pass directly reservationAdd() method.
even if condition is wrong else statements (reservationAdd()) running, how do you think I should go here ?
-
As noted in your previous thread, please don't cross-post the same question in multiple fora without providing links from one to the other. This goes against forum etiquette and may upset some forum members (many who would otherwise help you). Best of luck.
- 06-08-2009, 05:51 AM #3
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
you have to consider data type
"1", 1 are different
- 06-08-2009, 03:34 PM #4
Hi,
There are major logical loopholes in your code.
These things u need to do.
1.First,you catch everything into ArrayList.
ArrayList roomNumbers=null;
while(rs.next())
{
roomNumbers= new ArrayList();
roomNumbers.add(rs.getInt("odano"));
}
2.Then using for loop u check like this below
for(int i=0;i<roomNumbers.size();i++)
{
//check for roo not equal to null and check for integer then
if satisfied then typecast to int and retreive the arraylist value using rooNumbers.get(i) and convert to int and compare.
}Ramya:cool:
- 06-08-2009, 08:43 PM #5
Member
- Join Date
- Nov 2008
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
Comparing two data types in order to store in array
By gwithey in forum New To JavaReplies: 3Last Post: 05-01-2009, 10:27 AM -
Comparing two images
By GhosT in forum Advanced JavaReplies: 13Last Post: 04-25-2009, 12:37 AM -
Comparing Strings
By souFrag in forum Advanced JavaReplies: 5Last Post: 05-21-2008, 09:03 AM -
Comparing Strings
By Java Tip in forum Java TipReplies: 0Last Post: 12-03-2007, 09:44 AM -
comparing
By Feng in forum New To JavaReplies: 2Last Post: 11-23-2007, 09:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks