我有这样的代码来构建一个表时,我如何格式化日期变量错误的格式。它要么说日期不能保持整数或字符串。我如何输入日期以便它除外?以下是我尝试过的所有方法:插入到数据库表中使用的Java
INSERT INTO Course(CustomerName, Title, Type, Instructor, StartDate,EndDate,Price) VALUES ('Hary','Intro to Stupidity', 'Programming','Davis', 2017/11/12, 2017/04/03, 124.00);
INSERT INTO Course(CustomerName, Title, Type, Instructor, StartDate,EndDate,Price) VALUES ('Hary','Intro to Stupidity', 'Programming','Davis', 2017-11-12, 2017-04-03, 124.00);
INSERT INTO Course(CustomerName, Title, Type, Instructor, StartDate,EndDate,Price) VALUES ('Hary','Intro to Stupidity', 'Programming','Davis', 2017.11.12, 2017.04.03, 124.00);
INSERT INTO Course(CustomerName, Title, Type, Instructor, StartDate,EndDate,Price) VALUES ('Hary','Intro to Stupidity', 'Programming','Davis', (2017/11/12), (2017/04/03), 124.00);
如果有人能帮上忙,那就太好了!
简答题,不要。而应该使用'PreapredStatement'直接处理日期/时间类型的能力,并让底层驱动程序处理它 - 请参阅[使用预处理语句](https://docs.oracle.com/javase/tutorial/jdbc/basics/) prepared.html)了解更多详情 – MadProgrammer
您是否可能忘记使用“”来包围日期? – herokingsley
你使用什么数据库? Oracle,Postgre,Mysql等。如果您使用Oracle,请查看此链接:http://psoug.org/definition/to_date.htm – esprittn