Results 1 to 3 of 3
- 07-26-2007, 08:06 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Problems with Jtable connected to data base
I'm new in java and I have a problem with a Jtable.
I'm doing a windows that has a Jtable in a JScrollPane, it should shows information from data base, but it doesn't
this is the code
Java Code:public class Students extends JDialog { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JButton jButton1 = null; private JScrollPane jScrollPane = null; private JTable jTable = null; /** * @param owner */ public Students () { super(); initialize(); } private void initialize() { this.setSize(486, 230); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setContentPane(getJContentPane()); this.setLocationRelativeTo(null); } private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(getJButton1(), null); jContentPane.add(getJScrollPane(), null); } return jContentPane; } private JButton getJButton1() { if (jButton1 == null) { jButton1 = new JButton(); jButton1.setBounds(new Rectangle(174, 168, 100, 25)); jButton1.setText("Exit"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { Students . this.dispose(); } }); } return jButton1; } private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setBounds(new Rectangle(15, 16, 453, 131)); jScrollPane.setViewportView(getJTable()); } return jScrollPane; } private JTable getJTable() { if (jTable == null) { //jTable = new JTable(); DefaultTableModel model = new DefaultTableModel(); JTable jTable = new JTable(model); modelo.addColumn( "Name"); model.addColumn( "Number"); ResultSet rs; try { rs = Connection. st.executeQuery("SELECT name,nro FROM student order by name,nro"); while (rs.next()) { Object [] row = new Object[2]; for (int i=0;i<2;i++) row [i] = rs.getObject(i+1); model.addRow(row ); } } catch (SQLException ex) { JOptionPane.showMessageDialog( null, "Error "+ex, null, JOptionPane.ERROR_MESSAGE); } } return jTable; } }
- 07-26-2007, 08:41 PM #2levent Guest
Which exception do you get? We can't test this code on our side since we don't have your database. We can only help you to track the error if any.
- 08-07-2007, 04:24 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
Similar Threads
-
how to refresh data of the JTable
By paty in forum JDBCReplies: 3Last Post: 08-17-2008, 12:01 PM -
Problems when I try to connect to data base
By gabriel in forum JDBCReplies: 1Last Post: 08-06-2007, 05:38 PM -
problems with Instance Data
By paty in forum New To JavaReplies: 2Last Post: 08-02-2007, 05:45 PM -
2 threads sharing a data base connection
By Ed in forum Advanced JavaReplies: 2Last Post: 07-04-2007, 04:41 AM -
Connection to data base
By Daniel in forum JDBCReplies: 2Last Post: 06-07-2007, 04:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks