Can a Java application running on Window Server connect to SQL Server through Windows authentication?

Let me tell you before asking my question. Im in the store that runs windows first. We have several bundled applications running on Windows servers (mainly 2003). Most of these packaged applications are written in C # and C ++; however, we have several applications written in Java.

Java batch applications connect to a SQL Server 2005 database using JDBC. Please note that we do not use the application server.

We currently store database connection information (database, username and password) in the Windows registry.

Unfortunately, these really unfriendly auditors (poor attempt at humor) are unhappy with our decision to store information about connecting to the database in the Windows registry. Now we are updating our packaged applications to connect to SQL Server using Authentication.

Using Windows authentication for C # and C ++ applications is not a problem; however, I am stuck in the direction intended for Java applications.

Can anyone tell if Windows authentication can be used to connect to the SQL Server 2005 database from a Java batch application running on a Windows server? Again, we are not using an application server.

If possible, what are your recommended approaches?

I have a strategy to simply encrypt the password, which will make the auditors happy, however I would prefer that all my packaged applications connect to SQL Server through Windows Authentatication.

+4
source share
2 answers

You can connect to SQL Server from Java programs using Windows authentication as follows:

  • Create a Windows account for the application that will be used to run your programs. These credentials will be used to connect to the server.
  • Get the Microsoft JDBC driver for SQL Server here .
  • Configure the JDBC URL as follows:

    jdbc:sqlserver://<hostname>;databaseName=<DBName>;integratedSecurity=true 
  • Configure a startup program that starts Java programs from the command line to enable the following JVM option:

     -Djava.library.path="<jdbc driver dll location>" 

    where location is the directory in which the JDBC driver downloaded previously is installed or uninstalled. It was C:\Program Files\sqljdbc_4.0.2206.100_enu\sqljdbc_4.0\enu\auth\x64 in my case. As Luke Woodward noted in the comments, dll should be selected based on the JVM used to run these programs.

In the above configuration, the connection established for SQL Server will use the Windows authentication credentials of the domain user running the java program / process.

+6
source

The first step is to configure ODBC, you can go to Control Panel -> Administrative tools -> ODBC. Add a new DSN to connect to MS SQL Server using the Windows authentication account after configuring the wizard. The second step is similar to using a SQL Server authentication account. But the only change is that the connection string is changed to: jdbc: odbc: dsn-name. No need to use username / password anymore because it is already connected to the server.

0
source

Source: https://habr.com/ru/post/1434885/


All Articles