How to Connect to SQL Server Using Windows Authentication from Java Ee Webapp

Can I connect to SQL Server using Windows Authentication from Java EE webapp?

I do not think one can push the user credentials from the browser to the database (and does it makes sense ? I think not)

But if you want to use the credentials of the user running Tomcat to connect to SQL Server then you can use Microsoft's JDBC Driver.
Just build your JDBC URL like this:

jdbc:sqlserver://localhost;integratedSecurity=true;

And copy the appropriate DLL to Tomcat's bin directory (sqljdbc_auth.dll provided with the driver)

MSDN > Connecting to SQL Server with the JDBC Driver > Building the Connection URL

How to connect to SQL Server in windows authentication mode from Java EE Spring application?

Do you have JDBC driver library in your class path.? For j2ee it should be in the lib folder.

Jsf Project with Sql Server - Windows Authentication

Yes, it is possible.

You will need the sqljdbc_auth.dll. There's 3 places you can place it:

  1. in your WEB-INF/lib of the application
  2. In your Tomcat's lib folder
  3. In C:\windows\system32. Possible problems. The dll is distributed with the JDBC driver of Microsoft: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

In your connection string, use integratedSecurity=true; (example: jdbc:sqlserver://MyServer;databaseName=MyDatabase;integratedSecurity=true;)

Update 1: found this post on Stackoverflow for more info.

Connect To SQL Server With Windows Authentication From A Linux Machine Through JDBC

Well, eventually I answer my own question:
This is not possible to use Windows authentication from a linux machine using the Microsoft JDBC driver.
This is possible using the jTDS JDBC driver using the following connection string:

jdbc:jtds:sqlserver://host:port;databaseName=dbname;domain=domainName;useNTLMv2=true;

Thank you all for all the comments

SQL Server authentication using domain account from Java

While this question is closely related to the potential duplicate, I'm going to post my answer in the hope that it is helpful to someone in the future.

What we did was define a non-jndi data source:

<bean id="nonJndiDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driver" value="net.sourceforge.jtds.jdbcx.JtdsDataSource"/>
<property name="url" value="${url}"/>
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initial_size}"/>
<property name="maxActive" value="${max_active}"/>
<property name="maxWait" value="${max_wait}"/>
<property name="minIdle" value="${min_idle}"/>
<property name="maxIdle" value="${max_idle}"/>
</bean>

With the following properties file (that sets the values in the bean):

# Hibernate specific property
dialect=org.hibernate.dialect.SQLServer2008Dialect

# This is the key line
url=jdbc:jtds:sqlserver://127.0.0.1;databaseName=yourDatabase;useNTLMv2=true;domain=nameOfDomain

user=windows_account
password=password
initial_size=5
max_active=30
max_wait=600000
min_idle=0
max_idle=10

This can then be hooked into JDBC, Hibernate, JDBI, or some other JDBC based framework.

One gotcha at the time of this post is the version of jTDS. Version 1.3 requires Java 7 - we ended up pulling the jar for Version 1.2.x.

Can a Java application running on a Window's Server connect to SQL Server via Windows Authentication

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

  1. Create a windows account for the application that would be used to run your programs. This account's credentials will be used to connect to the server.
  2. Get Microsoft JDBC Driver for SQL Server from here.
  3. Configure the JDBC URL as follows:

    jdbc:sqlserver://<hostname>;databaseName=<DBName>;integratedSecurity=true
  4. Configure the launcher that run the Java programs from command line to include the following JVM parameter:

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

    where the location is the directory where the JDBC driver downloaded earlier is installed or extracted. It was C:\Program Files\sqljdbc_4.0.2206.100_enu\sqljdbc_4.0\enu\auth\x64 in my case. As Luke Woodward mentioned in the comments, the dll should be picked based on the JVM used for running these programs.

With the above configuration, the connection established to SQL Server would use the Windows Authentication Credentials of the domain user running the java program/process.

Java code to connect to MS SQL Server using service account and password

Are you using JTDS driver?

If so,

You have to pass user=abc;domain=CPD.Intr.Service;useNTLMv2=true

sql server 2005 connecting thru windows authentication

See Can I connect to SQL Server using Windows Authentication from Java EE webapp?

Has answers for both M$ & jTDS drivers



Related Topics



Leave a reply



Submit