javajtableapache-commons-dbutils

How to populate jTable using MS ACCESS on a button event?


Here is my Code: Its not displaying any data on Jtable please help me guys:

Connection con=null;

ResultSet rs=null;

PreparedStatement ps=null;
    try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection co=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=c:\\a.accdb");
          String sql="Select * from expenses";
              ps=con.prepareStatement(sql);
        rs=ps.executeQuery();
       Table_Expenses.setModel(DbUtils.resultSetToTableModel(rs));
   }
   catch(Exception e)
   {

   }

Solution

  • Replace

    rs=ps.executeQuery(sql);
    

    By

    rs=ps.executeQuery();
    

    EDIT:

    Now you failing to call your query

    Replace

    Connection co=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=c:\\a.accdb");
    

    By

    Connection con=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=c:/a.accdb");
    

    OR

    ps=con.prepareStatement(sql);
    

    By

    ps=co.prepareStatement(sql);