| | |
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
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream





