I've been kind of stuck with this for about a week now. I thought it would be just as easy in java as it is in PHP. Here goes:
After gathering data from the database and placing them in the JTable, I wanted to add a feature that could edit or delete a row in the JTable and in the database. Here's my code
private void getEmployees(String Query){
DefaultTableModel dm = new DefaultTableModel(0, 0){
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
String header[] = new String[] {"<html><b>ID</b></html>", "<html><b>Name</b></html>",
"<html><b>Birthday</b></html>", "<html><b>Department</b></html>",
"<html><b>Date Hired</b></html>", "<html><b>Position</b></html>" ,
"<html><b>Modify</b></html>"
};
dm.setColumnIdentifiers(header);
empList.setModel(dm);
empList.setRowSelectionAllowed(false);
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee?zeroDateTimeBehavior=convertToNull","root","passwords");
Statement stmt = conn.createStatement();
ResultSet rs;
rs = stmt.executeQuery(Query);
while(rs.next()){
Vector<Object> data = new Vector<Object>();
data.add(rs.getString("id"));
data.add(""+rs.getString("lName")+", "+rs.getString("fName"));
data.add(rs.getString("bday"));
data.add(rs.getString("dept"));
data.add(rs.getString("dateHire"));
data.add(rs.getString("position"));
data.add("Delete");
dm.addRow(data);
}
}
catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
See the data.add("Delete")? I've tried placing and href tag linked to a function but apparently it doesn't work. I also tried putting in a void function there but it doesn't accept void. I also tried using JButton and an EventListener but I keep getting lost in my track. I'm sorry for the stupid questions. I'm still a beginner hoping to learn more.