在用mybatis-plus的过程中,没排序就好好的,一旦排序,报如下错误:
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "." "."
at line 14, column 11.
Was expecting one of:
"&"
","
"::"
";"
"<<"
">>"
"ACTION"
"ANY"
"AS"
"BYTE"
"CASCADE"
"CAST"
"CHANGE"
"CHAR"
"CHARACTER"
"COLLATE"
"COLUMN"
"COLUMNS"
"COMMENT"
"COMMIT"
"CONNECT"
"CYCLE"
"DESC"
"DESCRIBE"
"DISABLE"
"DIV"
"DO"
"DUPLICATE"
"ENABLE"
"END"
"EXCEPT"
"EXCLUDE"
"EXTRACT"
"FALSE"
"FIRST"
"FN"
"FOLLOWING"
"FOR"
"FORMAT"
"FROM"
"GROUP"
"HAVING"
"INDEX"
"INSERT"
"INTERSECT"
"INTERVAL"
"INTO"
"ISNULL"
"KEY"
"LAST"
"MATERIALIZED"
"MINUS"
"NEXTVAL"
"NO"
"NOLOCK"
"NULLS"
"OF"
"OPEN"
"ORDER"
"OVER"
"PARTITION"
"PATH"
"PERCENT"
"PRECISION"
"PRIMARY"
"PRIOR"
"RANGE"
"READ"
"REPLACE"
"ROW"
"ROWS"
"SCHEMA"
"SEPARATOR"
"SEQUENCE"
"SESSION"
"SIBLINGS"
"SIZE"
"START"
"TABLE"
"TEMP"
"TEMPORARY"
"TO"
"TOP"
"TRUE"
"TRUNCATE"
"TYPE"
"UNION"
"UNSIGNED"
"VALIDATE"
"VALUE"
"VALUES"
"VIEW"
"WHERE"
"WINDOW"
"XML"
"ZONE"
"["
"^"
"|"
<EOF>
<K_DATETIMELITERAL>
<K_DATE_LITERAL>
<S_CHAR_LITERAL>
<S_IDENTIFIER>
<S_QUOTED_IDENTIFIER>
网上找了下,没找到解决方法,基本上都是说是if判断啥的有问题。。上面的错误细心一看,就能发现这应该是关键字冲突了。
带着这个思路,去找了下mysql的关键字:
ADD
ALL
ALTER
ANALYZE
AND
AS
ASC
ASENSITIVE
BEFORE
BETWEEN
BIGINT
BINARY
BLOB
BOTH
BY
CALL
CASCADE
CASE
CHANGE
CHAR
CHARACTER
CHECK
COLLATE
COLUMN
CONDITION
CONNECTION
CONSTRAINT
CONTINUE
CONVERT
CREATE
CROSS
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
CURRENT_USER
CURSOR
DATABASE
DATABASES
DAY_HOUR
DAY_MICROSECOND
DAY_MINUTE
DAY_SECOND
DEC
DECIMAL
DECLARE
DEFAULT
DELAYED
DELETE
DESC
DESCRIBE
DETERMINISTIC
DISTINCT
DISTINCTROW
DIV
DOUBLE
DROP
DUAL
EACH
ELSE
ELSEIF
ENCLOSED
ESCAPED
EXISTS
EXIT
EXPLAIN
FALSE
FETCH
FLOAT
FLOAT4
FLOAT8
FOR
FORCE
FOREIGN
FROM
FULLTEXT
GOTO
GRANT
GROUP
HAVING
HIGH_PRIORITY
HOUR_MICROSECOND
HOUR_MINUTE
HOUR_SECOND
IF
IGNORE
IN
INDEX
INFILE
INNER
INOUT
INSENSITIVE
INSERT
INT
INT1
INT2
INT3
INT4
INT8
INTEGER
INTERVAL
INTO
IS
ITERATE
JOIN
KEY
KEYS
KILL
LABEL
LEADING
LEAVE
LEFT
LIKE
LIMIT
LINEAR
LINES
LOAD
LOCALTIME
LOCALTIMESTAMP
LOCK
LONG
LONGBLOB
LONGTEXT
LOOP
LOW_PRIORITY
MATCH
MEDIUMBLOB
MEDIUMINT
MEDIUMTEXT
MIDDLEINT
MINUTE_MICROSECOND
MINUTE_SECOND
MOD
MODIFIES
NATURAL
NOT
NO_WRITE_TO_BINLOG
NULL
NUMERIC
ON
OPTIMIZE
OPTION
OPTIONALLY
OR
ORDER
OUT
OUTER
OUTFILE
PRECISION
PRIMARY
PROCEDURE
PURGE
RAID0
RANGE
READ
READS
REAL
REFERENCES
REGEXP
RELEASE
RENAME
REPEAT
REPLACE
REQUIRE
RESTRICT
RETURN
REVOKE
RIGHT
RLIKE
SCHEMA
SCHEMAS
SECOND_MICROSECOND
SELECT
SENSITIVE
SEPARATOR
SET
SHOW
SMALLINT
SPATIAL
SPECIFIC
SQL
SQLEXCEPTION
SQLSTATE
SQLWARNING
SQL_BIG_RESULT
SQL_CALC_FOUND_ROWS
SQL_SMALL_RESULT
SSL
STARTING
STRAIGHT_JOIN
TABLE
TERMINATED
THEN
TINYBLOB
TINYINT
TINYTEXT
TO
TRAILING
TRIGGER
TRUE
UNDO
UNION
UNIQUE
UNLOCK
UNSIGNED
UPDATE
USAGE
USE
USING
UTC_DATE
UTC_TIME
UTC_TIMESTAMP
VALUES
VARBINARY
VARCHAR
VARCHARACTER
VARYING
WHEN
WHERE
WHILE
WITH
WRITE
X509
XOR
YEAR_MONTH
ZEROFILL
然后写了点代码,检测了一下:
String sql = "SELECT\n" +
" \n" +
" a.id AS \"id\" ,\n" +
" a.code AS \"code\" ,\n" +
" a.keywords AS \"keywords\" ,\n" +
" a.description AS \"description\" ,\n" +
" a.url AS \"url\" ,\n" +
" a.title AS \"title\" ,\n" +
" a.price AS \"price\" ,\n" +
" a.sales AS \"sales\" ,\n" +
" a.thumbnails AS \"thumbnails\" ,\n" +
" a.shop_url AS \"shopUrl\" ,\n" +
" a.category AS \"category\" ,\n" +
" a.show AS \"show\" ,\n" +
" a.refresh_time AS \"refreshTime\" ,\n" +
" a.brand AS \"brand\" ,\n" +
" a.language AS \"language\" ,\n" +
" a.database AS \"database\" ,\n" +
" a.mobile AS \"mobile\" ,\n" +
" a.source_size AS \"sourceSize\" ,\n" +
" a.specification AS \"specification\" ,\n" +
" a.authorize AS \"authorize\" ,\n" +
" a.source_file AS \"sourceFile\" ,\n" +
" a.install_service AS \"installService\" ,\n" +
" a.host_type AS \"hostType\" ,\n" +
" a.pseudo_static AS \"pseudoStatic\" ,\n" +
" a.os AS \"os\" ,\n" +
" a.install_type AS \"installType\" ,\n" +
" a.web_service AS \"webService\" ,\n" +
" a.content AS \"content\" ,\n" +
" a.create_time AS \"createTime\" ,\n" +
" a.update_time AS \"updateTime\" ,\n" +
" a.update_by AS \"updateBy\" ,\n" +
" a.create_by AS \"createBy\" ,\n" +
" a.remark AS \"remark\" \n" +
" \n" +
" FROM xxxxxx a";
List<String> strings = FileUtil.readUtf8Lines("D:\\xxxx\\xxxxx\\mysql.txt");
for (String string : strings) {
String str = string.toLowerCase();
if(sql.contains(str)){
System.out.println("存在关键字:" + str);
}
}
用了hutool工具类,sql语句中还真存在mysql关键字,database,show,将这两个删除之后,排序正常!