0
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?

Erik A
  • 31,639
  • 12
  • 42
  • 67
asd32
  • 45
  • 3
  • 10
  • *"If in the line i add rs=pst.executeQuery(sql); The error is feature not supported."* - Yes, of course. That is not how you use a PreparedStatement. However, `pst.executeQuery();` should work correctly. – Gord Thompson Jun 20 '16 at 12:32
  • the program freezes with pst.executeQuery(); – asd32 Jun 20 '16 at 12:47
  • Try opening the database with "console.bat" or "console.sh" from the UCanAccess distribution. If the database opens successfully then try `SELECT COUNT(*) AS n FROM Synola;` and see if that returns the correct row count. – Gord Thompson Jun 20 '16 at 14:03
  • it show in the jtable n and 1 blank row.I do not see the already insered data from database. – asd32 Jun 20 '16 at 14:12
  • No, I meant running that `SELECT COUNT(*) AS n FROM Synola;` query from "console.bat" or "console.sh" via an OS command prompt. The idea is to determine if your issue has more to do with UCanAccess or more to do with getting the information into your jTable. – Gord Thompson Jun 20 '16 at 14:19
  • Please [edit] your question to show the current state of your code and how it (now) fails to meet your expectations. (Don't bury significant additional details in the comments where people might not see them.) – Gord Thompson Jun 20 '16 at 16:57

1 Answers1

2

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.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418