Note that there are some explanatory texts on larger screens.

plurals
  1. POHow keep ResultSet open in java?
    primarykey
    data
    text
    <p>I'm passing values for a java file which creates a JTable. </p> <p><code></p> <pre><code>ResultSet res = np.InvestmentByInvestType(IType); String tablename = "Investment By Invest Type"; int customAmt = np.showCustomizeInvestAmount1(IType); CommonTable ct = new CommonTable(); ct.CommonSearchTable(res, customAmt,tablename); </code></pre> <p></code></p> <p>I created a button in CommonSearchTable to export the JTable data using the ResultSet. But it showing error <b>"Operation not allowed after ResultSet closed"</b>. A method in CommonSearchTable.java is as below:</p> <p><code></p> <pre><code>public void CommonSearchTable( final ResultSet res, int totally, final String tablename) throws SQLException { JButton exportTable= new JButton ("Export"); ResultSetMetaData metaData = res.getMetaData(); // names of columns Vector&lt;String&gt; columnNames = new Vector&lt;String&gt;(); int columnCount = metaData.getColumnCount(); for (int column = 1; column &lt;= columnCount; column++) { columnNames.add(metaData.getColumnName(column)); } // data of the table Vector&lt;Vector&lt;String&gt;&gt; data = new Vector&lt;Vector&lt;String&gt;&gt;(); while (res.next()) { Vector&lt;String&gt; vector = new Vector&lt;String&gt;(); for (int columnIndex = 1; columnIndex &lt;= columnCount; columnIndex++) { vector.add(res.getString(columnIndex)); } data.add(vector); } model1 = new DefaultTableModel(data, columnNames); JTable table = new JTable(model1); int rows = table.getRowCount(); Sorter = new TableRowSorter&lt;DefaultTableModel&gt; (model1); table.setRowSorter(Sorter); showSearchPages(30, 1); table.setModel(model1); String showTotal = "Total Amount : Rs."+totally+"/-"; JPanel footer = new JPanel(); JLabel show = new JLabel(showTotal); box1.setBounds(10,30,800,30); show.setBounds(10, 60, 100, 30); show.setFont(new Font("Tahoma",Font.BOLD,16)); footer.add(box1); footer.add(show); footer.setPreferredSize(new Dimension(800,100)); JPanel holdingPanel = new JPanel(null); JScrollPane sp = new JScrollPane(table); JButton print = new JButton ("Print"); print.setBounds(10,10,100,30); exportTable.setBounds(120,10,100,30); sp.setBounds(10,50,780,580); holdingPanel.add(print); holdingPanel.add(exportTable); holdingPanel.add(sp); JFrame f = new JFrame("Search Results"); f.getContentPane().add(holdingPanel,BorderLayout.CENTER); f.getContentPane().add(sp.getVerticalScrollBar(),BorderLayout.EAST); f.getContentPane().add(footer,BorderLayout.SOUTH); f.setPreferredSize(new Dimension(850,680)); f.pack(); f.setLocationRelativeTo(null); f.dispose(); f.setResizable(false); f.setIconImage(img.getImage()); f.setVisible(true); exportTable.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent aev) { try { ExportFile ef = new ExportFile(); ef.WriteFile(res, tablename); } catch (SQLException | IOException ex) { Logger.getLogger(CommonTable.class.getName()).log(Level.SEVERE, null, ex); } } }); print.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); if (printJob.printDialog()) try { printJob.print(); } catch(PrinterException pe) { } } }); } </code></pre> <p></code></p> <p>Please show me the way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload