Note that there are some explanatory texts on larger screens.

plurals
  1. POCant display rows in a JTable (Values from Database)
    primarykey
    data
    text
    <p>Hello dear programmers,</p> <p>it's my first post and i hope i'm able to describe which kind of problem i have. I'm German, thats why my classnames are in german. I tried to put in some helpfull comments.</p> <p>I'm trying to put the values of a database (called "buchungen") into a JTable inside a JPanel. My JTable shows up but only the headers and no rows.. </p> <p>Here is my class with the JTable inside:</p> <pre><code>public class Verlauf extends SQL{ JTable table = new JTable(); DefaultTableModel model = new DefaultTableModel(); Verlauf(){ removeAll(); try { rs = stmt.executeQuery("SELECT * FROM buchungen WHERE Ausführer = '" + kontoNr + "'"); // kontoNr equals to Ausführer in the database } catch (Exception e) { e.printStackTrace(); } displayData(rs); repaint(); } public void displayData(ResultSet rs) { int i; int count; String a[]; String header[] = {"BuchungsNr","Ausführer","Betrag","Aktion","Empfänger"}; //Table Header Values, change, as your wish count = header.length; //First set the Table header for(i = 0; i &lt; count; i++) { model.addColumn(header[i]); } table.setModel(model); //Represents table Model add(table.getTableHeader(),BorderLayout.NORTH); a = new String[count]; // Adding Database table Data in the JTable try { while (rs.next()) { for(i = 0; i &lt; count; i++) { a[i] = rs.getString(i+1); } model.addRow(a); //Adding the row in table model table.setModel(model); // set the model in jtable } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Exception : "+e, "Error", JOptionPane.ERROR_MESSAGE); } } </code></pre> <p>I got the method for the jtable from a other post which i cant find anymore... I hope someone can help me :)</p> <p>Edit: The connection to my database is made in another class (called SQL) which works fine because i can use it from other classes perfectly in the same way i did here.</p> <p>Greetings Lukas Warsitz</p>
    singulars
    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