如何从hibernate + spring应用程序将csv文件导入到mysql中? [英] how to import a csv file into a mysql from an hibernate+spring application?

查看:88
本文介绍了如何从hibernate + spring应用程序将csv文件导入到mysql中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要将一个csv文件导入到一个mysql表中。因为我做了一个导入是因为我有很多大文件,这些文件以很短的时间间隔发送到我的服务器,尝试用java逐行添加,但得到了一堆不同的错误,如休眠异常或Java挂起,如果文件是太大。进口工作速度非常快,资源非常少。但我不知道如何通过Hibernate的HQL来构建查询来执行此操作,例如:

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 INFILE '"+filename+
    "' INTO TABLE testtable (text,price);

如果不能这样做,那么我该如何从执行此操作的方法运行shellcript ?

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

谢谢!

推荐答案

以完全回答你的问题,但Hibernate的本地查询工具可以让你加载一个文件。

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();

这篇关于如何从hibernate + spring应用程序将csv文件导入到mysql中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆