SQlite creating a database with a timestamp column and adding a value in

前端 未结 2 1775
悲&欢浪女
悲&欢浪女 2021-01-04 17:56

I am trying to create a database that called rawData. The db will hava a column for the id, a foreign user id (_id from another table), data and finally a timestamp.

2条回答
  •  无人及你
    2021-01-04 18:37

    This is a running example of DAO with SQlite and Date in Java:

    First create column MY_DATE TIMESTAMP in your TABLE and populate like this:

    PreparedStatement st = connection.prepareStatement("INSERT INTO ......");
    st.setDate(1, new java.sql.Date(lettura.getData().getTime()));
    

    And to retrieve data first i get date in String type:

    String dateStr = rs.getString(1);
    Date myDate = new java.util.Date(Long.parseLong(dateStr));
    

提交回复
热议问题