java - Add a mouseListener to a JTable having mysql data -


i have class,that takes values mysql database,i want add mouselistener has function:

-select row or cell on jtable , modify selected value or delete selected row.

-the changes made on jtable should visible in table of mysql database

it possible ? thanks.

 import java.awt.*;  import java.sql.*;  import java.util.*;   import javax.swing.*;   import databaseconnectionsingleton.connection;  import databaseconnectionsingleton.creationstatement;   public class showemployee extends jframe { /**  *   */ private static final long serialversionuid = 1l;  public showemployee() {     vector<string> columnnames = new vector<string>();     vector<vector<object>> data = new vector<vector<object>>();      try {          connection.getconnectioninstance();         statement st = creationstatement.getcreationstatementinstance();         resultset rs = st.executequery("select * employee");         resultsetmetadata md = rs.getmetadata();         int columns = md.getcolumncount();          // column names          (int = 1; <= columns; i++) {             columnnames.addelement(md.getcolumnname(i));         }          // row data          while (rs.next()) {             vector<object> row = new vector<object>(columns);              (int = 1; <= columns; i++) {                 row.addelement(rs.getobject(i));             }              data.addelement(row);         }     } catch (exception e) {         system.out.println(e);     }      // create table database data      jtable table = new jtable(data, columnnames) {         /**          *           */         private static final long serialversionuid = 1l;          public class<?> getcolumnclass(int column) {             (int row = 0; row < getrowcount(); row++) {                 object o = getvalueat(row, column);                  if (o != null) {                     return o.getclass();                 }             }              return object.class;         }     };      jscrollpane scrollpane = new jscrollpane(table);     getcontentpane().add(scrollpane);      jpanel buttonpanel = new jpanel();     getcontentpane().add(buttonpanel, borderlayout.south); }  public static void main(string[] args) {     showemployee frame = new showemployee();     frame.setdefaultcloseoperation(exit_on_close);     frame.pack();     frame.setvisible(true); } } 


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -