开发者

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

  1. just use insert n(rows).
  2. use StringBuilder mtrx and make large string with all data then executeUpdate(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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜