Connecting MATLAB and MySQL with the JDBC Driver

前端 未结 1 1844
难免孤独
难免孤独 2021-01-17 07:02

I bought the book Undocumented MATLAB by Yair Altmam; in chapter 2.2 of the book he discusses database connectivity and using the JDBC to connect to databases. I followed th

相关标签:
1条回答
  • 2021-01-17 07:43

    My first suspicion is your java class path. Instead of:

    javaclasspath('mysql-connector-java-5.1.30-bin.jar')
    

    Use

    javaaddpath('C:\full\path\to\mysql-connector-java-5.1.30-bin.jar')
    

    If that is not the problem, lets skip the DriverManager (doesn't really help much) and see if the code below works, (or where it fails).

    d = com.mysql.jdbc.Driver;
    urlValid = d.acceptsURL('jdbc:mysql://localhost:3306/test');  %Should return true
    props = java.util.Properties;
    props.put('user','root'); props.put('password','1234');
    con = d.connect('jdbc:mysql://localhost:3306/test',props)
    

    The DriverManager construct doesn't really help much. It seems to be designed to allow a developer to load up a bunch of drivers, and then connect to any supported database without knowing or caring what the DB implementation was (e.g. Mysql, Postgresql, Oracle etc.) I have never seen this as a useful feature. I think (hope?) that this is being used less in favor of a DataSource construct.

    Regardless, if this is your first time connecting Mysql to Matlab, you probably are best just directing using the provided Driver class.

    0 讨论(0)
提交回复
热议问题