嗨,我正在尝试使用hibernate将文件中的数据加载到Mysql DB。
这是查询,
session.createSQLQuery("LOAD DATA INFILE E:/uploaded/NumSerie/NS/NumSerie.txt INTO TABLE prod CHARACTER SET latin1 FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES;").executeUpdate();
但是我收到以下错误,
org.hibernate.QueryException: Space is not allowed after parameter prefix ':' [LOAD DATA INFILE E:/uploaded/NumSerie/NS/NumSerie.txt INTO TABLE prod CHARACTER SET latin1 FIELDS TERMINATED BY ';' LINES TERMINATED BY ' ' IGNORE 1 LINES;] at org.hibernate.engine.query.ParameterParser.parse(ParameterParser.java:92) at org.hibernate.engine.query.ParamLocationRecognizer.parseLocations(ParamLocationRecognizer.java:75)
如何重写此查询,以便正确执行此查询?
提前致谢!
尝试创建参数化查询
我不是Hibernate专家,但这可以工作:
session.createSQLQuery("LOAD DATA INFILE :file INTO TABLE prod CHARACTER SET latin1 FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES;") .setString("file", "E:/uploaded/NumSerie/NS/NumSerie.txt") .executeUpdate();