我有一个如下所示的字符串:
dd/mm/yyyy
我想将它输入到SQL数据库中
数据库字段(日期类型)将格式显示为yyyy-MM-dd。
目前我有以下代码:String inputDate = dateBookingEntry.getText();
LocalDate interDate = LocalDate.now();
interDate.parse(inputDate,DateTimeFormatter.ofPattern("dd/MM/yyyy"));
java.sql.Date finalDate = java.sql.Date.valueOf(interDate);
输入日期12/12/2020作为字符串时,得到错误消息:
你的SQL语法有一个错误;check the manual that corresponds to your MySQL server version for the right syntax to use near''2020-01-29'
SQL插入代码如下所示:st.executeUpdate("INSERT INTO `fitnessClasses`(`session`, `date`, `price`, `trainer`, `level`, `type`) VALUES ('"+session+"', '"+sqlDate+"', '"+price+"', '"+trainer+"', '"+level+"', '"+classType+"')");
上面提到的错误的完整SQL代码如下所示:ResultSet result = st.executeQuery("SELECT * FROM `fitnessClasses` WHERE `session` = '"+session+"' AND `date` '"+finalDate+"' AND `type` = '"+classType+"' AND `level` = '"+level+"'");