Win7 64-bit system Matlab access Mysql database (Details !), Win7matlab
Access Mysql database using Win7 64-bit system Matlab
PS: I have read a lot of technical posts on the Internet that use Matlab to connect to Mysql, but there are always problems with my own operations. Now I am writing a detailed technical post, hoping to avoid detours in the future! Some matlab database statements will be written later!
Instance:
I) download to get the mysql-connector-java-5.1.35-bin.jar;
Http://dev.mysql.com/downloads/connector/j/
Download: mysql-connector-java-gpl-5.1.35.msi (Don't worry this is 32-bit)
Run -- C: \ ProgramFiles (x86) \ MySQL Connector J -- mysql-connector-java-5.1.35-bin.jar
II) copy to the D: \ ProgramFiles \ Matlab \ R2009b \ java \ jar \ toolbox folder;
III) add a sentence to classpath.txt under path D: \ Program Files \ Matlab \ R2009b \ toolbox \ local to load the jdbc driver of mysql.
$ Matlabroot/java/jar/toolbox/mysql-connector-java-5.1.35-bin.jar, close matlab, re-open, everything OK.
Note: 1. Classpath.txt directly add $ MATLAB root/java/jar/toolbox/mysql-connector-java-5.1.35-bin.jar. Do not add above #
2. mysql-connector-java-5.1.35-bin.jar versions must be consistent
3. conn = database ('test', 'root', '123', 'com. mysql. jdbc. driver ', 'jdbc: mysql: // 127.0.0.1: 3306/test ')
Conn =
Instance: 'imgtograph'
UserName: 'root'
Driver: []
URL: []
Constructor: [1x1 com. mathworks. toolbox. database. databaseConnect]
Message: 'unable to find JDBC driver .'
Handle: 0
TimeOut: 0
AutoCommit: 'off'
Type: 'database Object'
Error: 'unable to find JDBC driver .'
Solution: 1. test must be the database name, not the connection name (when you find that the mysql-connector-java-5.1.35-bin.jar replication and classpath.txt are correct, check if your statement has a problem !)
2. Restart matlab
Conn = database ('20140901', 'root', '20160901', 'com. mysql. jdbc. Driver ', 'jdbc: mysql: // 127.0.0.1: 8080 ')
Conn =
Instance: '20140901'
UserName: 'root'
Driver: 'com. mysql. jdbc. Driver'
URL: 'jdbc: mysql: // 127.0.0.1: 8080'
Constructor: [1x1com. mathworks. toolbox. database. databaseConnect]
Message: []
Handle: [1x1com. mysql. jdbc. JDBC4Connection]
TimeOut: 0
AutoCommit: 'on'
Type: 'database Object'
Successful!
Mysq statement for matlab query:
Conn = database ('ryzh ', 'root', '000000', 'com. mysql. jdbc. Driver', 'jdbc: mysql: // 192.168.0.100: 9101/ryzh ')
SQL = ['select. date, B. symbol,. aum, B. endQty, B. tclose,. cs from a join B on. date = B. date where. date = curdate ()-1 ']
Curs = exec (conn, SQL );
Curs = fetch (curs)
Position = curs. data;
Note: 1. ryzh is the database name.
2. Write the SQL statement in a pair (put the SQL statement in NAVICAT to run it !! It cannot be run, that is, the statement has an error and the data cannot be read)
3. exec, fetch read is a struct
4. curs. data is data (in short, the data can be read only when SQL is correct)
Reference: 1. http://blog.sina.com.cn/s/blog_5071eb880100w1i3.html matlab connection mysql installation details!
2. http://www.blogjava.net/qileilove/archive/2014/05/08/413436.html matlab write mysql query statement paste!