MySql STR_TO_DATE在存储过程中不起作用

时间:2021-12-25 15:38:26

I want to add date from my JSP to mysql database using Servlet, if i write a query then STR_TO_DATE work properly for insertion, but if i use STR_TO_DATE in Stored Procedure it gives me "com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '11-10-2015' for column 'DATE' at row 1".

我想使用Servlet将JSP中的日期添加到mysql数据库,如果我编写查询然后STR_TO_DATE正常插入,但如果我在存储过程中使用STR_TO_DATE它会给我“com.mysql.jdbc.MysqlDataTruncation:数据截断:不正确日期值:'11 -10-2015',列'DATE'在第1行“。

My Query is:

我的查询是:

INSERT INTO TABLENAME (DATE) VALUES (STR_TO_DATE('01/01/2010','%d-%m-%Y'));" 

Any Idea?

2 个解决方案

#1


2  

The second parameter within the function STR_TO_DATE is using the wrong format. You need to use %d/%m/%Y instead of %d-%m-%Ybecause your date is formatted with / seperator.

STR_TO_DATE函数中的第二个参数使用了错误的格式。你需要使用%d /%m /%Y而不是%d-%m-%Y因为你的日期是用/ seperator格式化的。

INSERT INTO TABLENAME (DATE) VALUES (STR_TO_DATE('01/01/2010','%d/%m/%Y')); 

#2


0  

STR_TO_DATE requires the formatting of the strings to match:

STR_TO_DATE要求字符串的格式匹配:

INSERT INTO TABLENAME (DATE) VALUES (STR_TO_DATE('01/01/2010','%d/%m/%Y'));

Refer to the docs for full details.

有关完整详细信息,请参阅文档。

#1


2  

The second parameter within the function STR_TO_DATE is using the wrong format. You need to use %d/%m/%Y instead of %d-%m-%Ybecause your date is formatted with / seperator.

STR_TO_DATE函数中的第二个参数使用了错误的格式。你需要使用%d /%m /%Y而不是%d-%m-%Y因为你的日期是用/ seperator格式化的。

INSERT INTO TABLENAME (DATE) VALUES (STR_TO_DATE('01/01/2010','%d/%m/%Y')); 

#2


0  

STR_TO_DATE requires the formatting of the strings to match:

STR_TO_DATE要求字符串的格式匹配:

INSERT INTO TABLENAME (DATE) VALUES (STR_TO_DATE('01/01/2010','%d/%m/%Y'));

Refer to the docs for full details.

有关完整详细信息,请参阅文档。