JDBC Connection Exception with MS SQL Server 2008 - java

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)

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).

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

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).

Related

Failed to Connect to Database in SQL EXPRESS 2010 from Java Application

I am having problems trying to connect from a Java application (Netbeans IDE 8.0.2) to a database in SQL EXPRESS 2010. I know that the connection parameters are correct since if I try to make the connection running the application from Netbeans it works fine, but If I try to make the connection running the aplication with the .jar, the try-catch shows me the following error:
Com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId: ad61b2cf-071d-4561-9416-c31f8e918a34
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2400)
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<init>(AuthenticationJNI.java:68)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3132)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:43)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3123)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7505)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2445)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1981)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnectionInternal(SQLServerDataSource.java:704)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnection(SQLServerDataSource.java:54)
at sqlserver.SqlServer.checkNewConnection(SqlServer.java:67)
at view.Dialogs.configConnection(Dialogs.java:269)
at demosocketserial.DemoSocketSerial.checkConnection(DemoSocketSerial.java:211)
at demosocketserial.DemoSocketSerial.main(DemoSocketSerial.java:41)
Caused by: java.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<clinit>(AuthenticationJNI.java:41)
... 15 more
I already copied the sqljdbc_auth.dll file to the Windows System32 folder (that's how I made the connection successful from Netbeans) but I did not get the program to work from the .jar inside the "dist" folder.

unable to connect to Database from my java code

i keep on getting the following error when ever i try to run my code to check connection between java code and db.
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://192.168.1.100
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at StoredProcedure.main(StoredProcedure.java:19)
There's not really enough information here to help you. Check out this question for a good example on how to pose your question, and possibly find an answer.
Its' showing No suitable driver found. Check your jdk compatible driver version with sql server.
Check system requirements here
Both jdk 7 and jdk 8 compatible jar file

AMTU (Amazon Transport Utility) crashing and service not running

Having a problem running AMTU on a windows 7 Pro Machine.
It runs fine when it opens but it crashes after running a few days.
Here is the Crash Report.
2013-09-14 09:48:19,482 [pool-3-thread-3] com.amazon.merchants.services.RetrieverService - Unable to retrieve unacknowledged report information - MWS Request ID unknown
2013-09-14 09:48:19,482 [pool-3-thread-3] com.amazon.merchants.services.RetrieverService - MWS responded with an error: Internal Error
com.amazonaws.mws.MarketplaceWebServiceException: Internal Error
at com.amazonaws.mws.MarketplaceWebServiceClient.processErrors(MarketplaceWebServiceClient.java:2342)
at com.amazonaws.mws.MarketplaceWebServiceClient.invoke(MarketplaceWebServiceClient.java:2231)
at com.amazonaws.mws.MarketplaceWebServiceClient.invoke(MarketplaceWebServiceClient.java:2011)
at com.amazonaws.mws.MarketplaceWebServiceClient.getReportList(MarketplaceWebServiceClient.java:1206)
at com.amazon.merchants.services.RetrieverService.processReportCheck(RetrieverService.java:94)
at com.amazon.merchants.services.RetrieverService.run(RetrieverService.java:46)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I also cannot start the Windows Service called AMTU. Get the following Error:
The AMTU service on local computer has started and then stopped
I am suspecting its a Java version issue.
In the AMTU documentation it says "requires Java version 1.6.0 or later (listed as JDK/JRE - 6)" and links to http://www.oracle.com/technetwork/java/archive-139210.html. The link has many download links, but nothing listed "JDK/JRE - 6".
AMTU documentation: https://d28hcfptedr5ia.cloudfront.net/ug/AMTU_2.2_UserGuide.pdf
Any Ideas?
Thanks in advance.
The way I read this crash report, AMTU got an unexpected result from the MWS servers:
MWS responded with an error: Internal Error
It seems the error handling in AMTU is not good enough to gracefully handle a HTTP status 500, and there is not a lot you can do about this. You could put a HTTP proxy in between and catch a HTTP 500 on the line before it gets to the AMTU, replacing it with something that AMTU handles more gracefully (e.g. an empty XML result or a time out). It would be preferrable though that Amazon doesn't send those errors back, after all, a 500 is an error on their side of things.
I seriously doubt the Java version has anything to do with this, but just in case: You can still download JRE6 even though it is end-of-life:
Java 6 downloads
Please note that the true name of JRE6 is "Java SE runtime environment" and JDK6 is called "Java SE development kit". At the time of writing, the most current version is "update 45". You may need to uninstall Java 7 to make sure the AMTU actually uses the version you want it to. Please also note that since AMTU is a 32bit process, you will need the 32bit JRE even if it is run on a 64bit windows.

trouble connecting to oracle db through ojdbc

For those who are willing to read a bit, (skip to end for short version):
I am trying to connect my java app to a remote oracle database. with no luck I am using Mac 10.7.5 with IntelliJ Idea 12, java version "1.6.0_51" 64-bit. I have been trying to get this work all day with no success. I also was not able to use the 'DataSource' view in IntelliJ because of a missing shared dylib missing in java.library.path. I suspect the two issues are related.
I tried installing Oracle Instant Client 64-bit (including the jdbc files), copied the dylibs to /usr/lib/java and this got me close to solving the "DataSource" view issue with a different error:
java.lang.RuntimeException: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
java.io.EOFException
in RemoteUtil$RemoteInvocationHandler.invoke(RemoteUtil.java:219)
at com.sun.proxy.$Proxy115.connect(Unknown Source)
in LocalDataSource.getConnection(LocalDataSource.java:158)
Caused by: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
java.io.EOFException
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:209)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at com.sun.proxy.$Proxy114.connect(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
in RemoteUtil$RemoteInvocationHandler.invoke(RemoteUtil.java:211)
... 21 more
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:250)
at sun.rmi.transport.StreamRemoteCall.executeCal
So the journey continued and I tried using the 32bit version of the ojdbc .dylibs and .jars but then I ran into 'wrong architecture'when trying to connect to oracle db using IntelliJ's DataSource view.
I would like to keep everything consistent by using 32-bit since most of my apps use libraries that require 32-bit JVM.
tl;dr 'ers:
-Cannot connect to oracle db through IntelliJ Idea 12 DataSource view nor connect through java app using JDBC
-BackGround Info: Mac OSX 10.7.5, Java 1.6.0_51 64-bit, IntelliJ Idea 12, Remote Oracle 11G DB
-Tried both 32-bit and 64-bit versions of Oracle Instant Client with jdbc files, no luck
Any suggestions will be greatly appreciated!
Thank you
Additional Notes: I cannot connect through sqlplus either; i get the error ORA-21561: OID generation failed. Search results only point to fixing the /etc/hosts file which does not make sense for me since the db server is on a remote server and I am connecting using a TNS entry in /etc/tnsnames.ora
===UPDATE 1===
I made some progress on connecting through the java code. Using this code:
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:#hostname:port/service_name", "user", "password");
but received the error:
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
I CAN connect using this exact piece of code on my work machine through eclipse ide but not on my Mac laptop.
For Intellij/DataGrip 2018 DB connection via TNS I got
[08006][17002] IO Error: Invalid connection string format, a valid format is: "host:port:sid"
I find the problem in Oracle driver version: 11.2.0.4
I get "Test Connection > Succesful" using version 12.1.0.2
I can only encourage you to use the oracle thin jdbc client. There must be a very specific reason not to. With that you will likely have NO problems.

Trouble Deploying App From Tomcat to Sun Java Web Server 7...and I'm a .NET guy :(

I am trying to deploy an application that was developed in MyEclipse using Tomcat (originally 5.5 but works with 7) to our demo server (Sun Java Web Server 7). Unfortunately all of the people that had designed the application have left the company. So, here is what I know:
1) The application works as-is in MyEclipse on Tomcat
2) The application was successfully deployed to Sun Java Web Server in the past (presumably with the same build)
3) I can connect to the database from the server with sqldeveloper
4) The application uses: Java EE 5 and Spring framework
Application settings:
driver: oracle.jdbc.driver.OracleDriver
url jdbc:oracle:thin#xx.xx.x.xx:service
Here is the only error I am getting. I get a lot of warnings before and after though:
warning: CORE3283: stderr: com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
failure:
for host xx.xx.x.xxx trying to GET /application/login.jsp, service-j2ee reports: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source. at
com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319) at
com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) at
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) at
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) at
com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) at
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113) at
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79) at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:379) at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:455) at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:463) at
org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:187) at
gov.nyc.oer.dao.SiteConfigDao.getSiteConfig(Unknown Source) at
gov.nyc.oer.manager.SiteConfigManager.getSiteConfig(Unknown Source) at
gov.nyc.oer.manager.SiteConfigManager.afterPropertiesSet(Unknown Source) at
gov.nyc.oer.manager.SiteConfigManager.getValue(Unknown Source) at
org.apache.jsp.login_jsp._jspService(login_jsp.java:67) at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:80) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:917) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373) at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:457) at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:351) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:917) at
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:398) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:185) at
org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:169) at
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:183) at
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:138) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:217) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:185) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:255) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187) at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556) at
com.sun.webserver.connector.nsapi.NSAPIProcessor.service(NSAPIProcessor.java:160)
Server Configuration:
Java: Enabled
Java Home: ${WS_JDK_HOME}
Ignore Environment Class Path: Enabled
Class Path Prefix: None
Server Class Path:
${WS_INSTALL_ROOT}/lib/webserv-rt.jar
${WS_INSTALL_ROOT}/lib/pwc.jar
${WS_INSTALL_ROOT}/lib/ant.jar
${java.home}/lib/tools.jar
${WS_INSTALL_ROOT}/lib/ktsearch.jar
${WS_INSTALL_ROOT}/lib/webserv-jstl.jar
${WS_INSTALL_ROOT}/lib/jsf-impl.jar
${WS_INSTALL_ROOT}/lib/jsf-api.jar
${WS_INSTALL_ROOT}/lib/webserv-jwsdp.jar
${WS_INSTALL_ROOT}/lib/container-auth.jar
${WS_INSTALL_ROOT}/lib/mail.jar
${WS_INSTALL_ROOT}/lib/activation.jar
Class Path Suffix: ${WS_INSTALL_ROOT}/lib/ojdbc14.jar
JVM Options:
-Djava.security.auth.login.config=login.conf
-Xms128m -Xmx256m
-Djdbc.drivers=oracle.jdbc.driver.OracleDriver
Looks like your database connection is not defined on your sun java web server 7. On this website you can find out how to define it.

Categories