In my current project I have a jtable with 4 columns. I don't want store duplicate data in second column, so I check each row in the jtable before I store it into to database.
Here's my code:
String s="";
int row = table.getRowCount();
for (int i=0; i<row; i++)
{
s = table.getValueAt(i, 1).toString().trim();
if (name.getText().equals(s))
{
JOptionPane.showMessageDialog(null, "data alreadyexist.","message",JOptionPane.PLAIN_MESSAGE);
break;
} else {
add();
break;
}
}