SQL Servers uses two different types of authentication

  1. SQL Server Authentication: is using users who are created on the SQL Server
  2. Windows Authentication: is using users from Active Directory

This tutorial utilises JTDS to connect SQL Server which allows Windows Authentication

  • Download JTDS from http://jtds.sourceforge.net and extract
  • Copy jtds-x.x.x.jar to <TOMCAT-INSTALL>/lib
  • Edit <TOMCAT-INSTALL>/conf/server.xml file and add following between Context tags for the web app that needs connection
    To connect using

    • SQL Server Authentication
      <Resource
      	name="jdbc/myDS"
      	auth="Container"
      	type="javax.sql.DataSource"
      	driverClassName="net.sourceforge.jtds.jdbc.Driver"
      	url="jdbc:jtds:sqlserver://server:1433/mydatabase"
      	username="sqluser"
      	password="XXXXXX"
      	maxActive="20"
      	maxIdle="10"
      	maxWait="-1"
      	validationQuery="SELECT 1"
      />
      
    • Windows Authentication
      <Resource
      	name="jdbc/myDS"
      	auth="Container"
      	type="javax.sql.DataSource"
      	driverClassName="net.sourceforge.jtds.jdbc.Driver"
      	url="jdbc:jtds:sqlserver://server:1433;DatabaseName=mydatabase;useCursors=false;domain=DOM;username=sqluser;password=XXXXXX;user=sqluser"
      	username="sqluser"
      	password="XXXXXX"
      	maxActive="20"
      	maxIdle="10"
      	maxWait="-1"
      	validationQuery="SELECT 1"
      />
      
  • Restart Tomcat
Advertisements