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


Problem :

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

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

Thank you!



Solution :

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

Mysql Tutorials

Mysql Howto..

How do i get the results of a mysql query into html textbox

How to find total no of '1' in the table?

How to make a PHP page have two “column” regions?

How to grant connection and connect to phpmyadmin on server via mysql

How can I make a best-sellers list?

How to select rows[0] while inserting in node-mysql?

How to restrict/obfuscate MySQL value when querying

In MySQL, how to select empty records

MySQL: How many minutes ago was DB updated?

How can I write SQL for a table that shares the same name as a protected keyword in MySql? [duplicate]

How to import my hosted mysql database to my local host database?

How to avoid implicit conversion of MySQL (Truncated incorrect DOUBLE value)

How can I count registers that created in last 24 hours?

how to backup and restore mysql database using java

How to UPDATE just part of a text entry in mysql? [duplicate]

How do i retrieve matched string of a paragraph using php

How can we re-use the deleted id from any MySQL-DB table?

How to write a sql to get the record in this dynamic table? [closed]

How to insert data into a MySQL table in MyQuery (Delphi)

How to do nested sum in group by in optimized/one query in MYSQL?

How to combine data in multiple rows in mysql

time in array - how to convert to timestamp?

How read few columns of a table using dbReadTable

How do I export MySQL table to Excel with PHP?

how to use sum and count (both) in mysql

How to implement cascading deletion of hierarchical data in MySQL?

I don't understand this piece of MySQL notation and subsequently don't know how to do it in Postgresql

How to check if mysql queries succeeded

How to adjust display settings of mysql command line?

How to combine two similiar MySQL statements into one