import java.awt.*; import java.awt.Window; import java.awt.event.*; import java.io.*; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; import javax.swing.JOptionPane; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.event.*; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.DefaultListModel; public class Ncr_DB2Tbl_12c extends JInternalFrame { static int openFrameCount = 0; static final int offset = 20; public Ncr_DB2Tbl_12c( String ncrTable ) { super( ncrTable + " Table", true, true, true, true); setResizable(true); openFrameCount++; Vector columnNames = new Vector(); Vector data = new Vector(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String filename = "./tst_NCR.mdb"; String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; database+= filename.trim() + ";DriverID=22;READONLY=true}"; Connection connection = DriverManager.getConnection( database ,"",""); Statement db_statement = connection.createStatement(); // Read data from a table String sql = "Select * from " + ncrTable; Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( sql ); ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); try { DatabaseMetaData dmd = connection.getMetaData(); if (dmd.supportsBatchUpdates()) { // Batching is supported System.out.print( "Batching is supported" ); } else { // Batching is not supported System.out.print( "Batching is NOT supported" ); } } catch (SQLException e) {} // Get column names for (int i = 1; i <= columns; i++) { String colname = md.getColumnName(i); System.out.print("\ncolname: " + colname ); columnNames.addElement( md.getColumnName(i) ); } // Get row data while (rs.next()) { Vector row = new Vector(columns); for (int i = 1; i <= columns; i++) { row.addElement( rs.getObject(i) ); System.out.print(", "); //String columnValue = rs.getString(i); int coltype = md.getColumnType(i); System.out.print("\ncoltype: " + coltype ); } System.out.print("\n"); data.addElement( row ); } rs.close(); stmt.close(); } catch(Exception e) { System.out.println( e ); } JPanel topPanel = new JPanel(); topPanel.setBorder(new EmptyBorder(1,1,1,1)); topPanel.setLayout(new BorderLayout()); // Create table with database data JTable table = new JTable(data, columnNames); //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //tableDonnees = new JTable(donnees, nomColonnes); //ascenseur.getViewport().add(tableDonnees); //ascenseur.setBounds(10, 80, 500, 575); //add(ascenseur); JScrollPane scrollPane = new JScrollPane( table , ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setBounds(10, 80, 650, 650); //getContentPane().add( scrollPane ); //JPanel buttonPanel = new JPanel(); //buttonPanel.setSize(650, 650); topPanel.add(scrollPane, BorderLayout.NORTH); //topPanel.add(buttonPanel, BorderLayout.SOUTH); //topPanel.setResizeable(true); setContentPane(topPanel); pack(); setLocation( offset * openFrameCount, offset * openFrameCount); } }