Skip to content

Instantly share code, notes, and snippets.

@hohonuuli
Created October 28, 2017 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hohonuuli/7519fa707ff4bef92ae37223471dd653 to your computer and use it in GitHub Desktop.
Save hohonuuli/7519fa707ff4bef92ae37223471dd653 to your computer and use it in GitHub Desktop.
% DATABASE - connect to a SQL database
%
% Usage:
% c = database(url, user, password, driverName)
%
% Inputs:
% url = The database URL. e.g. jdbc:jtds:sqlserver://solstice.shore.mbari.org:1433/EXPD
% user = The user name to connect to the database
% password = THe password for user
% driverName = the name of the JDBC driver to use for the connection.
% e.g. 'net.sourceforge.jtds.jdbc.Driver' (optional)
%
% Outputs
% c = A java.sql.Connection object to your database. Remember to call
% close, either as 'close(c)' or c.close() when you are done with the
% connection.
%
% NOTES: In order to connect to a database, you will need the appropriate
% JDBC driver on the classpath. Most drivers do not work on Matlab's dynamic
% classpath. Instead add them to ~/.matlab/R2014b/javaclasspath.txt
% Brian Schlining
% 2014-10-08
if nargin == 4
d = eval(driverName);
end
c = java.sql.DriverManager.getConnection(url, user, password);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment