Why am I having trouble connecting to a SQL database using JDBC and Windows Authentication?
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Geoff Hayes
2014-9-19
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 个评论
Geoff Hayes
2014-9-19
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!