Hey guys i would love someone to help me with my project. I am trying to display all of the data from a database to a jtable using Eclipse.
When i run this code i dont get any errors and nothing shows on the jtable.
I watched and followed this guy's video guide ( Java prog#5. JTable- Populate JTable data from database in java Netbeans and Sqlite (mysql) - YouTube )
and i downloaded this file rs2xml.jar
*** I am new to programming and still working on my skills ***
Thanks (Heads up)
package foodpackage; import java.awt.Color; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import net.proteanit.sql.DbUtils; /*** * * @author sa00366 * */ public class Admin { String MSAccessDriver = "sun.jdbc.odbc.JdbcOdbc ".trim(); String MyDatabase = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\db\\Database.mdb"; Connection con = null; Statement st = null; ResultSet rs; PreparedStatement pst = null; private JFrame frmAdminis; private JTable table; private JButton btnButton; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Admin window = new Admin(); window.frmAdminis.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Admin() { initialize(); Update_Table(); } public void Update_Table() { try { String sql = "select * dog"; pst=con.prepareStatement(sql); rs = st.executeQuery(sql); table.setModel(DbUtils.resultSetToTableModel(rs)); Class.forName(MSAccessDriver); String db = "jdbc:odbc:Animal"; // db = database string stored // in the database con = DriverManager.getConnection(db); st = con.createStatement(); st.execute(sql); } catch (Exception ex) { } } /** * Initialize the contents of the frame. */ private void initialize() { frmAdminis = new JFrame(); frmAdminis.setResizable(false); frmAdminis.setTitle("Title "); frmAdminis.setBounds(100, 100, 1048, 547); frmAdminis.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmAdminis.getContentPane().setLayout(null); table = new JTable(); table.setBounds(61, 76, 794, 226); frmAdminis.getContentPane().add(table); btnButton = new JButton("button"); btnButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Update_Table(); } }); btnButton.setBounds(61, 391, 200, 50); frmAdminis.getContentPane().add(btnButton); } private static class __Tmp { private static void __tmp() { javax.swing.JPanel __wbp_panel = new javax.swing.JPanel(); } } }