Ok i have this method to get names from a database so i can put them in a combo box later. Here is my code for the method:
public void getContacts(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc
dbc:email";
String userName="";
String PWD="";
con=DriverManager.getConnection(url, userName,PWD );
stat=con.createStatement();
rs=stat.executeQuery("SELECT * FROM contacts");
}
catch(Exception ev){
JOptionPane.showMessageDialog(null,""+ev.getMessage());
}//end catch
showRecord(rs);
}//end getContacts
public void showRecord(ResultSet result){
try{
do{
String iD,id2="";
iD=rs.getString(1);
if(iD==id2){
break;
}
names[i]=rs.getString(2);
id2=iD;
System.out.println(names[i]);
rs.next();
i=i++;
}while(i<=0);
}
catch(Exception eve){
JOptionPane.showMessageDialog(null,""+eve.getMessage());
}//end catch
}//end resultset
------------
Ok thats it.. now i know the database is fine and everything since i have connected to it before. The error i get when i try runing this is "Invalid cursor state" which i have no idea what that is.
So can i please get some urgent help on this?
I know the loop is pretty wierd lol , is there a better way? What i have is a database table with and ID for first coloumn and Firstname for second colom. I want it to add all the names in that table to a string variable names[] and then stop when its all done.. this is the only way i see it working but im sure there is a better way. Thanks
alot.. and the sooner the help the better.!!!