asd32
asd32

Reputation: 45

How to show data from Access in the correct order?

String sql="select ID,Hmerominia,Agores,Pliromes,Eksoda,Zhta,Metaforika,Pliromimetafo,Epitages,Xondriki,Noiki,Plirominoiki  from  Synola";

 try{
    pst = conn.prepareStatement(sql);
    rs=pst.executeQuery();
   jTable1.setModel(DbUtils.resultSetToTableModel(rs));

   // JOptionPane.showMessageDialog(null, "Saved");

}catch(Exception ex){
    JOptionPane.showMessageDialog(null, ex);

}

Read from database is fixed now but the ID which is 1 to 312 the numbers on the jtable don't come in order as in database.How can i fix this?

Upvotes: 0

Views: 141

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123419

the ID which is 1 to 312 the numbers on the jtable don't come in order

The only way to guarantee the order in which rows are returned by a SQL statement is to include an ORDER BY clause. In your case you need to add ORDER BY ID to the end of your SQL statement.

Upvotes: 2

Related Questions