i have jtable with 2 column then i want to insert value of it to database;
i know it can be done with something like ..
int count=table.getRowCount();
for(int i=0;i<count;i++){
Object obj1 = table.getValueAt(i, 0);
Object obj2 = table.getValueAt(i, 1);
the problem is.. getRowCount doesn't know if the row is empty, then in database, that empty value will still inserted (and it will generate my auto increment value in database)
my question how to insert database from jtable, but the empty row will not inserted?
thanks a lot for any kind of help,,
if i asking too much please just give me a clue to handle the empty row ,
forgive my english
here's the broken method to add data to database
public void addToDatabase(){
for (int i=0;i<table.getRowCount();i++){
//#####################################
//maybe need something in here
if(table.getValueAt(i, 0)==null||table.getValueAt(i, 1) ==null){
return;
//and maybe need something not return, but to get the next row (Just.. maybe ...)
//#####################################
}else{
try{
Connection c = getCon("databasez");
PreparedStatement p = c.prepareStatement("INSERT INTO table_data VALUES (?,?)");
p.setString(1, table.getValueAt(i, 0).toString());
p.setFloat (Float.parseFloat(table.getValueAt(i, 1).toString()));
p.executeUpdate();
p.close();
}catch(Exception e){
JOptionPane.showMessageDialog(this, "THERE WAS AN INVALID DATA");
}
}
}
}