Я бы написал новый класс, определенный конвертированием, который имеет этот параметр.
import java.text.SimpleDateFormat;
import java.util.Date;
public class convertText {
public java.sql.Date formatStringToSQLDate(String strDate) throws Exception{
Date utilDate = new Date(); //DateFormat
SimpleDateFormat dfFormat = new SimpleDateFormat("dd.MM.yyyy"); // parse string into a DATE format
utilDate = dfFormat.parse(strDate); // convert a util.Date to milliseconds via its getTime() method
long time = utilDate.getTime(); // get the long value of java.sql.Date
java.sql.Date sqlDate = new java.sql.Date(time);
return sqlDate;
}
}
Впоследствии, чтобы использовать его следующим образом.
Connection dp = DriverManager.getConnection("jdbc:ucanaccess://" + Filepath + Filename);
Statement stat = dp.createStatement();
String sql = "INSERT INTO user_table (Name, Birth) VALUES(?, ?)"; //statement as string
PreparedStatement pstmt = dp.prepareStatement(sql);
pstmt.setString(1, textFieldVorname.getText()); //replaces the first '?'
pstmt.setDate(2, Date.formatStringToSQLDate(textFieldGeburtsdatum.getText())); //replaces the second '?'
pstmt.executeUpdate(); //executes the insert-query