Home > Back-end >  MyBatis query data over a long period is always an error in the past??
MyBatis query data over a long period is always an error in the past??

Time:09-30

The test code is as follows:

@ Test
Public void testHistoryData () throws a ParseException {

The DateFormat format=new SimpleDateFormat (" MM - dd yyyy - HH: MM: ss ");
The Date startDateTime=format. The parse (" 2020-04-01 00:00:00 ");
The Date endDateTime=format. The parse (" the 2020-04-01 05:00:00 ");

List Data=https://bbs.csdn.net/topics/mapper.findByTableName1 (
"Baseline_32_171", startDateTime,
EndDateTime);
Data. The forEach (s - & gt; {
System.out.println(s);
});
}

Mapper interfaces are as follows:
List FindByTableName1 (@ Param (" tableName ") String tableName,
@ Param (" startDateTime ") Date startDateTime,
@ Param (" endDateTime ") Date endDateTime
);


The XML file is as follows:


But the Java background error:
# # # Error querying the database. Cause: the mysql. JDBC. Exceptions. Jdbc4. MySQLSyntaxErrorException: You have an Error in your SQL syntax; Check the manual that corresponds to your MySQL server version for the right syntax to use near '?
The and? 'at line 6
# # # The error may exist in wnlbswit/SSM/mapper/BaselineMapper. XML
# # # The error may involve wnlbswit. SSM. Mapper. BaselineMapper. FindByTableName1
# # # The error occurred while executing a query
# # # SQL: select * from baseline_32_171 - where a DateTime & gt;=? - and DateTime & lt;=? Where a DateTime between? The and?
# # # Cause: com. Mysql. JDBC. Exceptions. Jdbc4. MySQLSyntaxErrorException: You have an error in your SQL syntax; Check the manual that corresponds to your MySQL server version for the right syntax to use near '?
The and? 'at line 6
; Bad SQL grammar []; Nested exception is com. Mysql. JDBC. Exceptions. Jdbc4. MySQLSyntaxErrorException: You have an error in your SQL syntax; Check the manual that corresponds to your MySQL server version for the right syntax to use near '?
The and? 'at line 6


Could you tell me where is the problem! Feel the XML files do not have what problem, who can help me with it

CodePudding user response:

BETWEEN
DATE_FORMAT (# {startDateTime} '% % Y - m - H: % d % % I: % s')
AND
DATE_FORMAT (# {endDateTime} '% % Y - m - H: % d % % I: % s')

CodePudding user response:

 select * from baseline_32_171 - where a DateTime & gt;=? - and DateTime & lt;=? Where a DateTime between? The and? 

Why logging of SQL with "-- where a DateTime & gt;=? - and DateTime & lt;=?" This is a piece of

CodePudding user response:

reference 1st floor xiaoqian8705 response:
BETWEEN
DATE_FORMAT (# {startDateTime} '% % Y - m - H: % d % % I: % s')
AND
DATE_FORMAT (# {endDateTime} '% % Y - m - H: % d % % I: % s')
like or not, feeling parameter didn't passed in

CodePudding user response:

refer to the second floor waste seven years response:
 select * from baseline_32_171 - where a DateTime & gt;=? - and DateTime & lt;=? Where a DateTime between? The and? 

Why logging of SQL with "-- where a DateTime & gt;=? - and DateTime & lt;=?" This paragraph
this is my previous conditions, comments, don't know why the log will have

CodePudding user response:

reference 1st floor xiaoqian8705 response:
BETWEEN
DATE_FORMAT (# {startDateTime} '% % Y - m - H: % d % % I: % s')
AND
DATE_FORMAT (# {endDateTime} '% % Y - m - H: % d % % I: % s')
done well, thank you
  • Related