I am trying to insert to my table, a date in format "yyyy-mm-dd". My table has a field date type DATETIME and I use SQLite DB SYSTEM. I need to be in this format, so later to have the option to select dates from - then.
My table:
CREATE TABLE "IsSELECTED"(
"date" DATETIME PRIMARY KEY NOT NULL DEFAULT (CURRENT_DATE) ,
"morning" BOOL NOT NULL DEFAULT (0) ,
"noon" BOOL NOT NULL DEFAULT (0) ,
"night" BOOL NOT NULL DEFAULT (0)
)
and the method which i am trying to insert.
public void setTodayInfo(HttpSession session, Date date)
throws SQLException, ClassNotFoundException {
System.out.println("Initialize today's info...");
String sq = "INSERT INTO IsSELECTED (date, morning, noon, night) VALUES (?, ?, ?, ?)";
try {
Class.forName(typeDB);
c = DriverManager.getConnection(path);
stm = c.prepareStatement(sq);
PreparedStatement stm = c.prepareStatement(sq);
stm.setDate(1, date);
stm.setBoolean(2, FALSE);
stm.setBoolean(3, FALSE);
stm.setBoolean(4, FALSE);
int rowsAffected = stm.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (stm != null) {
stm.close();
}
if (c != null) {
c.close();
}
}
}
How can i create a variable (DATE) with the format "yyyy-mm-dd" ?
Aucun commentaire:
Enregistrer un commentaire