我从jDateChooser捕获用户日期输入以插入mssql表时遇到问题。 stackoverflow中存在类似的问题。它没有解决我的问题。
以下是我捕获用户日期条目的代码
obj.setStartDate(jDateChooser3.getDate());
obj.setEndDate( jDateChooser4.getDate());
DatabasePropeties类和SaveNewProject方法
import java.math.BigDecimal;
import java.sql.*;
import java.util.Date;
Date StartDate;
Date EndDate;
public boolean SaveNewProject()
{
boolean resp = false;
paTable = connector();
try {
String SPsql = "EXEC AddNewProject ? ,? ,? ,? ";
PreparedStatement cmd = cnuser.prepareStatement(SPsql);
cmd.setString(1, ProjectName);
cmd.setDate(2, StartDate);
cmd.setDate(3, EndDate);
cmd.setString(4, ProjectCode);
if (!cmd.execute()) {
resp = true;
}
cmd.close();
paTable.close();
} catch (Exception ex) {
System.out.println("Error" + ex.getMessage());
}
return resp;
}
Setters and Getters
public Date getStartDate() {
return StartDate;
}
public void setStartDate(Date StartDate) {
this.StartDate = StartDate;
}
public Date getEndDate() {
return EndDate;
}
public void setEndDate(Date EndDate) {
this.EndDate = EndDate;
}