0

您好我正在尝试使用休眠将文件中的数据加载到 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)

如何重写此查询以便正确执行?

提前致谢!

4

1 回答 1

4

尝试创建参数化查询

我不是 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();
于 2012-04-27T13:24:57.357 回答