String[] header = {"Name", "Age", "Place", "Date of Birth","Qualification"};
table_model = new DefaultTableModel(header, 3);
table = new JTable(table_model);
JScrollPane sp = new JScrollPane(table);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
table.setFillsViewportHeight(true);
JButton submit = new JButton("Submit");
jp1.add(new JScrollPane(table));
jp1.add(submit, BorderLayout.WEST);
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
TableCellEditor editor=table.getCellEditor();
editor.stopCellEditing();
Connection con = DriverManager.getConnection(host, uName, uPass);
stmt = con.createStatement();
for(int i=0;i<table.getRowCount();i++){
String name = table.getValueAt(i,0).toString();
int age = Integer.parseInt(table.getValueAt(i,1).toString());
String place=table.getValueAt(i,2).toString();
String dob=table.getValueAt(i,3).toString();
String qualification=table.getValueAt(i,4).toString();
stmt.execute("insert into PERSONAL(NAME,AGE,PLACE,DOB,QUALIFCATION)values('"+name+"',"+age+",'"+place+"',"+dob+",'"+qualification+"')");
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
});
i created a table with three rows and four columns.if i enter all values in three rows and column it will be successfully submitted.if any empty value enter in any row or column or user leaves all rows and column empty it is showing null pointer exception.But how to handle this.if user enter any null value or leaves all cells empty.it want to display a message please enter some value.after filling all values in three rows only it will allow.how to achieve thhis