开发者

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

开发者 https://www.devze.com 2023-03-15 23:36 出处:网络
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 l

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

精彩评论

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

关注公众号