better way to insert a matrix into a MYSQL table
I have a Java program which will produce a large matrix, at the end I want to save that matrix to a DATABASE 'MYDATABASE'
in a myMatrixTable
My first thoughts as newbie were
- just use insert n(rows).
- use
StringBuilder mtrx
and make large string with all data thenexecuteUpdate(mtrx.toString());
is there a better way to save a matrix ?
If the matrix is very big, another option would be to write it into a file, then use LOAD DATA INFILE
syntax to load it to the DB. This gives better performance for large sets of data.
See manual here: http://dev.mysql.com/doc/refman/5.1/en/load-data.html
EDIT:
In case the matrix is small (not many rows), I would go for the first option, looping over the rows and using INSERT
, which is way more elegant and readable than the second option.
精彩评论