2

I am using windows server 2003 on VM vare on which I have my database on MS SQL Server 2008 . Now when I used jdbc driver to connect my java code with database I am getting following exception. Kindly give some solution .

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.microsoft.sqlserver.jdbc.AuthenticationJNI.SNISecGenClientContext([B[I[BI[B[I[ZLjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/util/logging/Logger;)I
    at com.microsoft.sqlserver.jdbc.AuthenticationJNI.SNISecGenClientContext(Native Method)
    at com.microsoft.sqlserver.jdbc.AuthenticationJNI.GenerateClientContext(AuthenticationJNI.java:80)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2691)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at test.jdbcdemo.main(jdbcdemo.java:24)
5
  • Related: stackoverflow.com/q/175055/738746 Commented Jun 17, 2012 at 18:19
  • Which JDBC driver, and what connection URL are you using? Commented Jun 17, 2012 at 19:35
  • 1
    Can you show your connection string? Is SQL Server on the same machine as the Java code? Is it a named instance or a default instance? Are you sure the service is running? Are you using Windows auth or SQL auth? Are you sure you can ping the server correctly, that the right ports are open, etc.? Has this ever worked on this machine, or is this a new program and your first attempt to connect, or has something on the machine, the code, or SQL Server changed? Why does JDBC produce such meaningless and useless error messages? Commented Jun 18, 2012 at 1:25
  • I am using default instance and services are running and there is windows authentication.Port is default 1433. String dbtime; String dbClass = "com.mysql.jdbc.Driver"; String query = "Select * FROM [eSchool].[dbo].[tblClass]"; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection ("jdbc:sqlserver://localhost;databaseName=eSchool;integratedSecurity=true"); Statement stmt = (Statement) con.createStatement(); ResultSet rs = ((java.sql.Statement) stmt).executeQuery(query); Commented Jun 18, 2012 at 4:46
  • Is your VM on a domain? I can reproduce this error on my home PC with Windows 7 Home Premium, and it's not on a domain. Commented Aug 3, 2013 at 15:36

3 Answers 3

1

You have enabled integratedSecurity. This means that the sqljdbc_auth.dll needs to be on the library path of the jvm.

Most likely you do not have this library on your path, it is the wrong version or the wrong variant (x86 <> x64 <> IA64).

Sign up to request clarification or add additional context in comments.

Comments

0

An old question but I had this issue today. I don't know the first thing about Java but for me the fix was to copy Microsoft's JDBC driver to Java's ext folder.

sqljdbc41.jar needs to be copied to C:\[path to java installation]\Java\jre7\lib\ext\

Make sure you pick the right version (x86 or x64).

Also for Integrated Security I needed to make a reference to auth when starting my application.

-Djava.library.path=C:\[Path to Microsoft JDBC Driver 4.1 for SQLServer]\sqljdbc_4.1\enu\auth\x86

Comments

0

I had the same exception when starting SpringBatch with an JdbcBatchItemWriter writing to MS SQL Server 2008.

Sqljdbc_auth.dll was on the library path. It turned out that I was running my SpringBatch application in Eclipse with JRE 1.6. I solved this by running it with JRE 1.7 (Eclipse JRE-Tab in Run-Configurations).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.