如何将 java Date 对象插入 Postgresql DATE 单元格?
当我按照自己的方式做时,这是错误的:
Calendar date = Calendar.getInstance(); // wrong
Date date = new Date(); // wrong
String addRecord = "INSERT INTO " + GlobalFields.PACJENCI_TABLE +
"VALUES (" + date + ");";
stat.executeUpdate(addRecord)
我没有更多的想法...
PS:
public static void CreatePacjenciTable()
{
try
{
Connection conn = DataBase.Connect();
try
{
Statement stat = conn.createStatement();
String createTable = "CREATE TABLE " + GlobalFields.PACJENCI_TABLE
+ "(dataUrodzenia DATE);";
stat.executeUpdate(createTable);
}
finally
{
conn.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}