I'm facing a small issue with SQL dates and java which I already search the world on internet about this. The thing is that my program must load all the dates from a SQL table to my Java jtable. I might have to use some sort of conversion from date to string.
I tried by using conversion like this records[0]=rs.getDate("mydate").toString();
but no luck with this.
private void load(String value){
Conector cc= new Conector();
Connection cn= cc.conexion();
//java.util.Date date= new java.util.Date();
//SimpleDateFormat sdf= new SimpleDateFormat("dd/MM/yyyy");
String [] titles={"Dates"};
String [] records;
records = new String[1];
String sql="SELECT * FROM turns WHERE dates LIKE '%"+value+"%'";
model= new DefaultTableModel(null,titles);
try {
Statement st= cn.createStatement();
ResultSet rs= st.executeQuery(sql);
while (rs.next()) {
records[0]=rs.getDate("mydate").toString();
model.addRow(records);
}
tablaturnos.setModel(model);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error:"+e, "Error Message", JOptionPane.ERROR_MESSAGE);
}
}
Any help is appreciated.