| | |
Inserting into jtable
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 28
Reputation:
Solved Threads: 0
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:
JAVA Syntax (Toggle Plain Text)
public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); loadDB(); } }); } catch (Exception ex) { ex.printStackTrace(); } } public void loadDB() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c = DriverManager.getConnection("jdbc:odbc:testy1"); Statement s = c.createStatement(); ResultSet rs = s.executeQuery("select * from song_library"); while (rs.next()) { jTable2.add(rs.getString(2),new Label()) ; } } catch (Exception e) { } }
A way to add rows to JTable :
Hope this will help you.
java Syntax (Toggle Plain Text)
// Header Object[] col = new Object[]{"Col1","Col2"}; // Data Object[][] data = {}; // Blank DefaultTableModel model = new DefaultTableModel(data,col); JTable table = new JTable(model); // OR table.setModel(model); // Adding Rows model.addRow(new Object[]{"Data1","Data2"});
Hope this will help you.
Puneet Kalra
www.PuneetK.com
Sun Certified Java Programmer
Admin of Pikk - Object Relational Mapping Framework
www.PuneetK.com
Sun Certified Java Programmer
Admin of Pikk - Object Relational Mapping Framework
![]() |
Similar Threads
- deleting rows from a JTable (Java)
- How to make JTable cell not Editable (Java)
- JTable Reloading/Refreshing/Updating/Whatever. (Java)
- Jtable (Java)
- Adding and deleting a column in JTable (Java)
- JTable problem (Java)
- help with inserting a number into an array (C++)
- JTable not calling getValueAt - any ideas? (Java)
- Saving and opeing a JTable (Java)
- Drawing A Table On A Container(Panel) (Java)
Other Threads in the Java Forum
- Previous Thread: any collections of how to BUILd OR MAKE JAVA applications
- Next Thread: i need sollution
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api append apple applet application arguments array arrays automation bi binary bluetooth busy_handler(null) chat class classes clear client code component database draw eclipse ee error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaprojects jmf jni jpanel julia jvm key lego linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nextline notdisplaying number object oracle output print problem program programming project qt recursion repositories robot scanner screen se server set singleton size sms socket sort sql stream string swing terminal test textfields threads time transfer tree windows wrong





