Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

better way to insert a matrix into a MYSQL table

Tags:

java

mysql

matrix

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 ?

like image 668
Ismail Marmoush Avatar asked Feb 03 '26 21:02

Ismail Marmoush


1 Answers

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.

like image 144
Galz Avatar answered Feb 05 '26 12:02

Galz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!