Actually , i must admit , i did not knew about connecting with database but i am trying to learn , i want to insert data into jtable from Ms acess database , i have made a table called song_library there and also created the dsn as testy1...Also in the in init function where the jTable is called i have written the code for connecting to the databse!! And i also know there is some problem i my code, i am posting that part of the code here:

public void init() {
        try {

            java.awt.EventQueue.invokeAndWait(new Runnable() {

                public void run() {

        } catch (Exception ex) {
    public void loadDB()
           try {
            Connection c = DriverManager.getConnection("jdbc:odbc:testy1");
            Statement s = c.createStatement();
            ResultSet rs = s.executeQuery("select * from song_library");
            while ( {
                jTable2.add(rs.getString(2),new Label()) ;

        } catch (Exception e) {


A way to add rows to JTable :

// Header
			Object[] col = new Object[]{"Col1","Col2"};
			// Data
			Object[][] data = {}; // Blank
			DefaultTableModel model = new DefaultTableModel(data,col);
			JTable table = new JTable(model);
			// OR
			// Adding Rows
			model.addRow(new Object[]{"Data1","Data2"});

Hope this will help you.

This article has been dead for over six months. Start a new discussion instead.