【发布时间】:2017-11-04 23:22:45
【问题描述】:
我正在尝试读取 Excel 日期值并将其存储到我的数据库中。
以下代码是我得到的:
Date birthdate = null;
case 8:
birthdate = cell.getDateCellValue();
break;
switch case是将Date存储在一个变量中,之后再放入一个数组中。
Identity id = new Identity(BSN, sort, birthdate, place);
我将这些值中的多个存储到一个数组列表中。
for(Identity id : Identities) {
System.out.println(id.toString());
idmc.insertID(""+id.getBSN(), id.getSort(), id.getBirthdate(), id.getPlace());
}
日期的 getter 和 setter 很明显,但我会发布它以防万一。
public void Birthdate (Date birthdate) {
this.birthdate = birthdate;
}
public Date getBirthdate() {
return birthdate;
}
然后插入我从数组中得到的值,我使用这个方法:
public String insertID(String BSN, String SoortID, Date UitgiftedatumID, String UitgifteplaatsID) {
String returning = null;
try {
query = "insert into Identiteit values(?,?,?,?);";
pst = connection.prepareStatement(query);
pst.setInt(1, Integer.parseInt(BSN));
pst.setString(2, Sort);
pst.setDate(3, birthdate);
pst.setString(4, place);
int response = pst.executeUpdate();
returning = response +" Records has/have been edited";
} catch (SQLException e) {
returning = " ";
}
return returning;
}
但是,这行:pst.setDate(3, UitgiftedatumID); 说:Incomatible types: java.util.Date cannot be converted to java.sql.Date.
我尝试过像:pst.setDate(3, (java.sql.Date) UitgiftedatumID);
但不幸的是,这对我来说并不奏效。
【问题讨论】: