필터 지우기
필터 지우기

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.

답변 (1개)

Geoff Hayes
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
Mathew
Mathew 2014년 9월 19일
편집: Mathew 2014년 9월 19일
Thanks Geoff,
That gets me a lot closer. Running what you posted above:
driver = com.microsoft.sqlserver.jdbc.SQLServerDriver; connectionUrl= 'jdbc:sqlserver://Host:1434;database=DB;integratedSecurity=true;'; props = java.util.Properties; ConnectionCon = driver.connect(connectionUrl,props);
Gives me the following error:
Error using BasisConnect (line 16) Java exception occurred: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host Host, port 1434 has failed. Error: "connect timed out. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
When running methodsview(com.microsoft.sqlserver.jdbc.SQLServerDriver), I see: throws com.microsoft.sqlserver.jdbc.SQLServerException
This makes me think that I don't have the right DB properties. When looking at the DB properties in Microsoft SQL Server Management Studio, I can comfirm the Host is right under "Name", but don't know how to varify the port or database name.
Geoff Hayes
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 CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by