开发者

how to import a csv file into a mysql from an hibernate+spring application?

i want to do an import of a csv file into a mysql table. The reason im doing an import is becuase i have many big files, that are sent to my server in short intervals, tried with java adding line by line, but got a bunch of different errors, like hibernate exceptions or java hung if the file was too big. Imports works very fast, very well with very little resources. But i don´t know how can i build a query through hibernate's HQL to do this, something like:

LOAD DATA INFIL开发者_JAVA技巧E '"+filename+
    "' INTO TABLE testtable (text,price);

if this can´t be done, then how can i run a shellscript from the method that do this ?

Thank you!


Not sure I have enough information to fully answer your question, but Hibernate's Native Query facilities might let you load a file that way.

session.createSQLQuery("LOAD DATA INFILE :filename INTO TABLE testtable (text,price)").setString("filename", "/path/to/MyFile.csv").executeUpdate();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜