Come faccio a mettere la mia tabella così costituita:
in un JInternalFrame????codice:public void TableSQL() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /////////////////////////////////////////////// // n° di colonne int columns = 6; // etichette colonne String[] labels = {"postazione", "data_ora", "udt", "articolo","lotto","quantita"}; // larghezza colonne int[] widths = {60, 120, 70, 100, 80, 70}; try { String driver = "net.sourceforge.jtds.jdbc.Driver"; Class.forName(driver).newInstance(); } catch (Exception e) { JOptionPane.showMessageDialog(null,"Fallito il caricamento dei driver SQL.","ERRORE CARICAMENTO DRIVER SQL",JOptionPane.ERROR_MESSAGE); } try { Connection con1=null; String postazione=selectedItem; String tempo_min=data_inizio; String tempo_max=data_fine; // Query SQL String SQL_rows="SELECT count (postazione) FROM log_lavorazione_baie where quantita=1598"; String SQL= "SELECT * FROM log_lavorazione_baie where quantita=1598 ORDER BY data_ora DESC"; //DB BECHELLI Connessione col database in cui vengono specificati url, nome utente, password con1 = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/master", "user", "pw"); Statement select1=con1.createStatement(); Statement select = con1.createStatement(); //caricamento query SQL ResultSet result2=select.executeQuery(SQL_rows); result2.next(); int ris_row=result2.getInt(1); // n° di righe dinamico rows = ris_row; result1 = select.executeQuery(SQL); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null,"Connessione col database fallita","ERRORE CONNESSIONE DATABASE",JOptionPane.ERROR_MESSAGE); } // vettore dati tabella Vector data = new Vector(0, 1); // vettore colonne tabella Vector columnNames = new Vector(0, 1); // popolo la tabella for(int i = 0; i < rows; i++) { try { // vettore singola riga tabella Vector row = new Vector(); result1.next(); for (int j = 1; j <= columns; j++) { try { row.addElement(result1.getString(j)); } catch (SQLException ex) { Logger.getLogger(ControlloLog.class.getName()).log(Level.SEVERE, null, ex); } } data.addElement(row); } catch (SQLException ex) { Logger.getLogger(ControlloLog.class.getName()).log(Level.SEVERE, null, ex); } } // intestazioni colonne for(int i = 0; i < columns; i++) { columnNames.addElement(labels[i]); } // modello dati della tabella DefaultTableModel tableModel = new DefaultTableModel(data, columnNames); // modello attributi delle colonne DefaultTableColumnModel columnModel = new DefaultTableColumnModel(); for(int i = 0; i < columns; i++) { // modello attributi colonna singola TableColumn column = new TableColumn(i, widths[i]); column.setHeaderValue(labels[i]); columnModel.addColumn(column); } // la tabella JTable table = new JTable(tableModel, columnModel); table.setPreferredScrollableViewportSize(new Dimension(500, 300)); JScrollPane scroll = new JScrollPane(table); /////////////////////////////////////////////////// getContentPane().add(scroll); pack(); setVisible(true); }

Rispondi quotando