![](/img/trans.png)
[英]com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: ' '
[英]com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value
谁能指导我在 MySQL 数据库中执行查询代码,我在 JSP 项目中工作,当我尝试执行查询时,出现以下异常:
com.mysql.jdbc.MysqlDataTruncation: 数据截断: 不正确的日期值: '%-12-31' for column 'dft' at row 1
代码:
try {
connexion = ServletCalendrier.getConnexion();
if(connexion == null) {
System.err.println("Une demande de connexion a ete faite au serveur mais n'a pas abouti");
}
initFeries();
String anneePlus = Integer.parseInt(annee)+1+"%";
query ="DELETE FROM TgCalFac WHERE annee LIKE '"+anneePlus+"' AND versionFac LIKE '"+version+"' AND dft LIKE '%-12-31'";
result = Queries.executeQuery(query);
connexion = ServletCalendrier.getConnexion();
pstmt = connexion.prepareStatement("SELECT count(*) as nombre FROM TgDft");
rset = pstmt.executeQuery();
if(rset.next())
nbJoursDft = rset.getInt("nombre");
pstmt.close();
pstmt = null;
// Insertion du premier lot
dft = new Dft(OperationsSurDates.stringToDate(String.valueOf((Integer.valueOf(annee)-1)) + "-12-31","yyyy-MM-dd"));
drmf = new Drmf(dft.getDft());
extraction = new Extraction(drmf);
ps2 = new PS2(extraction,ps2Prec);
dateFacture = new DateFacture(ps2);
delai1 = OperationsSurDates.differenceDates(dateFacture.getDateFacture1(), dft.getDft());
delai2 = OperationsSurDates.differenceDates(dateFacture.getDateFacture2(), dft.getDft());
drmf1Type = 0;
if(drmf.isDrmf1R()){
drmf1Type = 1;
}
if(drmf.isDrmf1L()){
drmf1Type = 2;
}
drmf2Type = 0;
if(drmf.isDrmf2R()){
drmf2Type = 1;
}
if(drmf.isDrmf2L()){
drmf2Type = 2;
}
而不是%
使用DAYOFMONTH ie : for day 和MONTH ie :for month ,因为您的year
值可以是任何东西。所以您的查询将如下所示:
query ="DELETE FROM TgCalFac
WHERE
annee LIKE '"+anneePlus+"'
AND
versionFac LIKE '"+version+"'
AND DAYOFMONTH(dft) = 31 AND MONTH(dft) = 12";
在此处检查示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.