1

I am using Java - eclipse with oracle SGBD

In my database there is a column of type Date.

I stored data in dd/mm/yyyy format. Didn't put any time there and it doesn't show any time when I view table data oracle console.

But in my application java, when I pull data using JTable ...it shows dd/mm/yyyy hh:mm:ss AM/PM (example- 12/04/2012 00:00:00 AM)

Why does it show the time? How can I remove that time part & show just the date ?

Please help

thats the methode I used to fill Table

public DefaultTableModel getJoueurData() {

    Vector<Vector<String>> data;
    Vector<String> colum;

    data = new Vector<Vector<String>>();
    colum = new Vector<String>();
    colum.add("id_j");
    colum.add("nom");
    colum.add("prenom");
    colum.add("DATE_NAISSANCE");
    colum.add("NATIONALITE");

    String query = "select id_j,nom,prenom,DATE_NAISSANCE,nationalite from joueur order by id_j";

    try {

        Connection conn = ReportDriver.connectDB(DB_CONNECTION, DB_USER,
                DB_PASSWORD);
        stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        Vector<String> vstring = null;
        while (rs.next()) {

            vstring = new Vector<String>();

            vstring.add(rs.getString("id_j"));
            vstring.add(rs.getString("nom"));
            vstring.add(rs.getString("prenom"));
            vstring.add(rs.getString("date_naissance"));
            vstring.add(rs.getString("nationalite"));
            vstring.add("\n\n\n\n\n\n\n");

            data.add(vstring);
        }

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException ex) {

            }
        }
    }

    DefaultTableModel d = new DefaultTableModel(data, colum);
    return d;

}
mugiwaradz
  • 393
  • 1
  • 3
  • 15
  • To understand a java.sql.Date, read [my answer](http://stackoverflow.com/a/24661790/642706) to another question. – Basil Bourque Jul 13 '14 at 16:00
  • possible duplicate of [java sql date time](http://stackoverflow.com/questions/8530545/java-sql-date-time). And [this](http://stackoverflow.com/q/13982870/642706) – Basil Bourque Jul 13 '14 at 16:02

1 Answers1

1

Instead of

vstring.add(rs.getString("date_naissance"));

you need something like this:

java.sql.Date date = rs.getString("date_naissance");
java.text.DateFormat df = java.text.DateFormat.getDateInstance();
vstring.add(df.format(date));
Sergiy Medvynskyy
  • 11,160
  • 1
  • 32
  • 48
  • yeeeeep ... thanks Bro thats exactely what i want there is just a micro-error in your code java.sql.Date date = rs.getDate("date_naissance"); not getString and thanks again – mugiwaradz Jul 13 '14 at 12:20