I have web based application and have MSSQL server 2012 and need to access that database using window authentication and using Tomcat 6 and OS Windows
But same functionality work fine (window authentication) with MSSQL server 2008 not MSSQL server 2012. So may i know the reason is there some thing miss in configuration.
i put jtds-1.2.5.jar in apache\lib directory and also put the ntlmauth.dll in C:\Windows\System32 location and also added the system variable "JAVA_OPTS" for the dll location but it does not work. It gives the error message :
2014-10-14 13:35:35,237 ERROR Unable to get database connection: SQL Exception occurred
java.sql.SQLException: Cannot open database "Test" requested by the login. The login failed.
Then i put the dll in jre\bin directory but it does not work please let is any wrong am doing.
Also try put the dll in apache\bin loc still getting the same issue.
But as per the client requirement that want using JTDS api not the Microsoft driver so need solution in JTDS api. Although it work fine MSSQL server 2008 but does not work in MSSQL server 2012.
I follow the link http://www.dekho.com.au/dekho-connecting-to-sql-server-using-windows-authentication/
we had similar problems with JDTS and at some point resorted to using the official JDBC driver from Microsoft. The Microsoft Driver works on Windows, Linux and MacOS and did not require me to put any DLLs or something like this anywhere.
http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx
The only downsides to this driver are (1) it is not open source so you cannot change it in case you need to, and (2) you need to accept a license. However (2) should not be a problem since you are using MSSQL Server anyways.
Finally (I am not sure if this applies to you) the Microsoft driver cannot be used with Maven. So I (on a Mac) use the following bash script to install the driver into my local Maven repository.
#!/bin/bash
mvn install:install-file -Dfile=lib/sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=3.0 -Dpackaging=jar
For the JDBC Connection strings see the following webpage:
http://msdn.microsoft.com/en-us/library/ms378428(v=sql.110).aspx
In your case since you want to do Windows authentication you need to make sure that you add
;integratedSecurity=true;
to the jdbcUrl.
Related
Good day,
What I have in mind:
I have rented a server (Ubuntu 22.04) and installed a mysql server there (8.0.32-0ubuntu0.22.04.2). I now wanted to run a jar file on the server (Java: OpenJDK Runtime Environment build 18.0.2-ea+9-Ubuntu-222.04) which automatically writes data to my database.
Problem:
When I ran the mysql server on the home computer with the jar program on the PC it worked without any problems.
When I accessed the Mysql server on the server from my home computer, I was also able to write data automatically.
When I now tried to execute the jar file on the server in order to access the Mysql server on the server, I always received the error message:
"No suitable driver found for jdbc:mysql://localhost".
What I have done so far:
-I enabled port 3306 in the firewall.
-I tried to specify the IP address of my server instead of jdbc:mysql://localhost (jdbc:mysql://XXXXXXX).
-I have inserted the jar file for the Connector/J 8.0.32 (Platform Independent) into my IntelliJ project.
-My user for the mysql server has admin rights and the password is also correct.
Now I don't know what to do. From my PC, I can use the jar file to automatically write data to the mysql server on the server, so the connector/j should work, but it doesn't work with the jar file on the server.
If you doesnt have the connector/J library into your jar file, just add this dependency in your pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
I am trying to install Snowflake JDBC driver according to instructions.
I have downloaded and installed Java from here, then downloaded snowflake-jdbc-3.6.9.jar file from here. When I double-click the file, nothing happens. So I opened CMD and tried this:
java -jar snowflake-jdbc-3.6.9.jar
I received *no main manifest attribute, in snowflake-jdbc-3.6.9.jar*.
When I open META-INF\MANIFEST.MF file, I do see:
*Manifest-Version: 1.0*
*Main-Class: net.snowflake.client.jdbc.SnowflakeDriver*
I have gotten this far using suggestions from other StackOverflow topics, and don't know what else to try. I don't know much about Java, I just need to install this driver, so I could connect to Snowflake from a BI tool. I would really appreciate your help.
I presume you got it up and running by now.
But as mentioned by one of the other responders, by copying the .jar file to your computer you have already more or less installed the driver.
Different from OBDC drivers, there is no JDBC manager, which expects that JDBC drivers need always to be installed in a certain directory.
You have to point the used application to this driver to use this driver.
Let's take as an example dBeaver, a popular JDBC Query tool among Snowflaker users. (And available for Windows, Mac and Linux)
Before you can use this driver within dBeaver, dBeaver has to be made aware that this driver does exist and can be used.
So after starting up dBeaver you first point dBeaver to the location where you have put the Snowflake .jar file.
(Let's assume that you don't want to use the preconfigured Snowflake JDBC driver for the sake of usefulness of my answer)
So you select New and select 'create new driver'
Under the windows [Libraries] you can add a file or a folder.
Select [Add File] and point at your JDBC .jar file.
As of then you can use the JDBC driver.
For completeness are here the other details to use a different Snowflake JDBC driver than the provided one in dBeaver:
[Driver Type:] Snowflake
[Class Name:] net.snowflake.client.jdbc.SnowflakeDriver
[URL Template:] this contains the default connectstring format to use this JDBC driver (So how a connectstring should look like to make a successful connection to Snowflake)
[Default Port:] 443 (should have been preset)
The rest should be self explanatory.
Have you tried adding the jar to classpath and then running the following command, Class.forName("provided driver name") in the calling class? Doing this with an IDE like Eclipse or Netbeans should make this process much simpler (particularly adding the jar to your project classpath)
Couple of solutions to the above:
1) Using CLASSPATH:
MacOS/Linux: EXPORT CLASSPATH="Path/to/JDBCjarfile:$CLASSPATH"
Windows: There are a couple of way of setting the CLASSPATH
a) Run the following in CMD:
set CLASSPATH=path1;path2
b) In Search, search for and then select: System (Control Panel)
Click the Advanced system settings link.
Click Environment Variables. In the section System Variables, find the CLASSPATH environment variable and select it. Click Edit. If the CLASSPATH environment variable does not exist, click New.
In the Edit System Variable (or New System Variable) window, specify the value of the CLASSPATH environment variable. Click OK. Close all remaining windows by clicking OK.
Reopen Command prompt window, and run your java code.
Document reference: https://www.java.com/en/download/help/path.xml
To confirm if the CLASSPATH variable is EXPORTED or SET:
1) MacOS/Linux:
$ echo $CLASSPATH
2) Windows:
$ echo %CLASSPATH%
I'm using Maven on NetBeans to import H2 Database to my project and the following code to init. a simple embedded database:
//...
Class.forName("org.h2.Driver");
//...
connection = DriverManager.getConnection("jdbc:h2:~/MCUsers");
//...
When I run the code on my Windows machine (where I do the programming), it works fine and I can create tables and rows. But when I run the same JAR file on my Linux machine, I get the following error:
Error Code:90020 Message:Database may be already in use: null.
Possible solutions: close all other connection(s); use the server mode
[90020-194] Cause:java.lang.IllegalStateException: The file is locked:
nio:/root/MCUsers.mv.db [1.4.194/7]
The same JAR runs on my Windows machine with no problems.
There are no other Java programs running on my Linux machine.
I already tried to reboot the system - didn't work.
Only The files MCUsers.mv.db & MCUsers.trace.db are created in the root directory after this error occurs.
My Linux machine uses JRE1.8.0_112 to execute the JAR file.
Edit:
Adding "FILE_LOCK=NO;" also didn't work.
I have two web-applications which need to run on Tomcat 6, MS SQL 2008 and JTDS-1.2.2 as driver.
If I start only one web application everything is working fine, but as soon as I start the second one I get the following error (it does not matter the order):
java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library
Of course, the library ntlmauth.dll is under C:\WINDOWS\system32
It seems that the second application which starts is not able to find the ntlmauth.dll for the single sign on.
I got past this by changing the url from
jdbc:jtds:sqlserver://host_server:1433/Database_name
to
jdbc:jtds:sqlserver://host_server:1433/Database_name;user=XXX;password=YYY
Apparently, "When URL [does] not contains user and password properties, systems uses Windows authentication method, and "SSPI Native library not found" error appears."
This is the solution:
Download the jTDS driver, unzip it, and copy x86\SSO\ntlmauth.dll to jdk\jre\bin.
This should solve your issue.
Edit:
Without the JDK installed the path for me was C:\Program Files\Java\jre7\bin\ntlmauth.dll
jTDS must be able to load the native SPPI library (ntlmauth.dll). Place this DLL anywhere in the system path (defined by the PATH system variable) and you're all set.
If you are trying to run two (or more) Tomcat applications on the same server that both access a SQL Server using the JTDS driver and windows authentication, a very helpful answer courtesy of Chris White is here.
Chris' answer has to do with sqljdbc_auth.dll, but the recommendations are the same for the JTDS driver and ntlmauth.dll:
Put ntlmauth.dll into the tomcat 7.0\bin directory. Actually, I believe you can put ntlmauth.dll into any directory in the system path, or the Java jre\bin directory.
Importantly, don't bundle the JTDS jar in the war file of any Tomcat application using the JTDS driver. Instead, put one copy in the Tomcat\lib directory, where Tomcat will load it and make it available to all apps.
If you are on 64-bit windows but running 32-bit java (the one in program files x86) then you need the 32-bit ntlmauth dll and not the 64 bit one that you might have expected.
I have a problem connecting to IBM (universal) database using JDBC. I wrote the code in Notepad using Java and I loaded drivers of IBM database i.e(driver name and connection URl). When I run the code using general compilation (javac code.java and java code) I am getting an error message "cannot find the driver" but I specified the correct driver name for that. Actually I did this program using Eclipse using the same database with same driver name and all and finally I succeeded, but I cant get this without using an IDE. So please help me how to connect without the IDE and how to run it in a command prompt.
You need to include the necessary JAR files on the classpath when you run your program on the command line.
If you're using IBM's DB2 UDB database, the required driver file is db2jcc.jar, and I think db2jcc_license_cisuz.jar and db2jcc_license_cu.jar are necessary for licensing as well. Search for those files, and include them on the classpath when you run your program from the command line.