I have a similar setup working in MATLAB that uses java to connect to MySQL and Access databases. I created a java class with the following method
public void openMySQLConnection(String userName, String userPassword, String databaseUrl){ try { Class.forName ("com.mysql.jdbc.Driver").newInstance (); conn = DriverManager.getConnection (databaseUrl, userName, userPassword); }catch (SQLException e) {System.err.println ("Cannot connect to database server");} }
This is done over the internal network since the comments defining databaseUrl glnd2818898.network.net are the MySQL server and it connects to the matlab database
The access interface is similar to
private static final String accessDBURLPrefix = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; private static final String accessDBURLSuffix = ";READONLY=true}"; public void openConnAccess(String userName, String userPassword, String databaseUrl){ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String dbUrl = accessDBURLPrefix + databaseUrl + accessDBURLSuffix; conn = DriverManager.getConnection (dbUrl, userName, userPassword); }catch (SQLException e) {System.err.println ("Cannot connect to database server :" + e.getMessage());} }
This is probably not the clearest java encoding since it was my first attempt from the point of view of MATLAB users, but it works for me.
source share