Getting value from table by mouse click
Hi,
I am totally new to Java, and a novice in programing all together....
For a big final project at school I have to develop an application to deal with data - store, retrieve, edit, print and so on..
I managed to connect to mySQL database and get a resultset, and display the result in a table format.
The next step is: When the user select any line with a mouse click, the row corresponding to the primary key (column 1) should be displayed in a textArea field.
My question: how do I get the value where the mouse was clicked?
My code (so far):
// Getting the resultSet:and put it in the table (that was created by NetBeans 5.5)
public Vector<Vector><Object>> getData() {
Vector<Vector><Object>> vtrEmployee = new Vector<Vector><Object>>();
try {
String query = "SELECT * FROM tblemployees ";
rs = stmt.executeQuery(query);
while (rs.next()) {
rowCode = rs.getString("empCode");
rowTitle = rs.getString("empTitle");
rowFirstName = rs.getString("empFName");
rowLastName = rs.getString("empLName");
rowNick = rs.getString("empNick");
rowDOB = rs.getString("empDOB");
rowStartWork = rs.getString("empStartWork");
rowAddress = rs.getString("empAddress");
rowSalary = rs.getInt("empSalary");
rowPass = rs.getString("empPass");
rowAccessLevel = rs.getInt("empAccessLevel");
rowRemark = rs.getString("empRemark");
Vector<Object> rowVector = new Vector<Object>();
rowVector.add(rowCode);
rowVector.add(rowFirstName);
rowVector.add(rowNick);
vtrEmployee.add(rowVector);
}
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
return vtrEmployee;
}// End getData()
//Selecting the wanted Line
public String selectLine(String selectedEmp) {
try {
String query = "SELECT * FROM tblemployees WHERE empCode = '" + selectedEmp + "';";
System.out.println("rowCode = " + rowCode);
rs = stmt.executeQuery(query);
while (rs.next()) {
String rowCode = rs.getString("empCode");
String rowTitle = rs.getString("empTitle");
String rowFirstName = rs.getString("empFName");
String rowLastName = rs.getString("empLName");
String rowNick = rs.getString("empNick");
String rowDOB = rs.getString("empDOB");
String rowStartWork = rs.getString("empStartWork");
String rowAddress = rs.getString("empAddress");
int rowSalary = rs.getInt("empSalary");
String rowPass = rs.getString("empPass");
int rowAccessLevel = rs.getInt("empAccessLevel");
String rowRemark = rs.getString("empRemark");
selectedEmp = "Code: " + rowCode +
"\nName: " + rowTitle + " " + rowFirstName + " " + rowLastName + " (" + rowNick + ") " +
"\nDOB: " + rowDOB + "\nWorking Since: " + rowStartWork + "\nAddress: " + rowAddress +
"\nSalary: " + rowSalary + "\nPassword: " + rowPass + "\nAccess Level: " + rowAccessLevel +
"\nRemarks: " + rowRemark ;
}
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
return selectedEmp;
}//End selectLine()
And this is the mouse click even that is supposed to return the empCode variable to the selectLine()
private void rtrvTableMouseClicked(java.awt.event.MouseEvent evt) {
txtAreaResults.setText(Employee.selectLine(<How do I get the value for here?>));
}
Any simple solution for this?
Many thanks in advance..

