Why am I having trouble connecting to a SQL database using JDBC and Windows Authentication?
8 views (last 30 days)
Show older comments
I am using the following to try to connect to a SQL database:
javaclasspath('C:\Program Files\Matlab\sqljdbc_2.0\enu\sqljdbc4.jar')%Driver location
java.lang.System.load('C:\Program Files\Matlab\sqljdbc_2.0\enu\auth\x64\sqljdbc_auth.dll');%Library
driver = com.microsoft.sqlserver.jdbc.SQLServerDriver;
conn = driver.connect('jdbc:sqlserver://Host:1434;database=DB');
I get this error:
No method 'connect' with matching signature found for class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'.
Error in BasisConnect (line 13)
conn = driver.connect('jdbc:sqlserver://Host:1434;database=DB');
Any idea what's going on? I've also tried connecting using COM and .NET to no avail. I think the lack of password from the Windows Authentication is throwing those off.
Thanks in advance.
0 Comments
Answers (1)
Geoff Hayes
on 19 Sep 2014
Mathew - if, in the Command Window, you type
methodsview(com.microsoft.sqlserver.jdbc.SQLServerDriver)
what do you see?
I can't run the above, but a window for the class com.microsoft.sqlserver.jdbc.SQLServerDriver may appear listing all available methods. If this happens, look for connect. What is its signature?
The error message, No method 'connect' with matching signature found for class, is suggesting that the inputs you are proving to the connect method are incorrect or insufficient. Are additional input parameters needed?
The link at Creating a Connection by Using the SQLServerDriver Class indicates that a second input is required
Driver d = (Driver)
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").
newInstance();
String connectionUrl =
"jdbc:sqlserver://localhost;database=AdventureWorks;integratedSecurity=
true;"
Connection con = d.connect(connectionUrl, new Properties());
The above isn't MATLAB code but it does point to the new Properties() as the second input to connect.
See also SQLServerDriver connect method which shows the function signature (for this version of connect) as
public java.sql.Connection connect(java.lang.String Url,
java.util.Properties suppliedProperties)
Maybe all you have to do is something like
driver = com.microsoft.sqlserver.jdbc.SQLServerDriver;
props = java.util.Properties;
conn = driver.connect('jdbc:sqlserver://Host:1434;database=DB',props);
2 Comments
Geoff Hayes
on 19 Sep 2014
Have you verified that SQL Server has been setup correctly? At this example they describe a similar problem to yours (different port of 1433 and error was "connection refused") but some of what they propose may be useful.
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!