How to create a JDBC Data Source with Tomcat 5 to connect to MS SQL Server

  1. Copy the driver jar file to $CATALINA_HOME/common/lib/.
  2. Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to $CATALINA_HOME/conf/server.xml.
  3. Add this before the </Host> tag closing the localhost definition.
    <Context path="/{context}" docBase="{context}" debug="5"
             reloadable="true" crossContext="true">
     
            <Resource name="jdbc/MS SQL" auth="Container" type="javax.sql.DataSource"/>
            <ResourceParams name="jdbc/MS SQL">
     
                    <!-- MS SQL dB username and password for dB connections -->
                    <parameter>
                            <name>username</name>
                            <value>{user}</value>
                    </parameter>
                    <parameter>
                            <name>password</name>
                            <value>{password}</value>
                    </parameter>
     
                    <!-- Class name for i-net MS SQL JDBC driver -->
                    <parameter>
                            <name>driverClassName</name>
                            <value>com.inet.tds.TdsDriver</value>
                    </parameter>
     
                    <!-- The JDBC connection URL for connecting to your MS SQL dB. 
                         If you use more as one parameter then you need to
                         concatenate with XML coded & like &amp; -->
                    <parameter>
                            <name>url</name>
                            <value>jdbc:inetdae7:{host}?database={database}</value>
                    </parameter>
            </ResourceParams>
    </Context>
  4. There are some placeholders you must replace with values specific for your environment.
    • {context} - is the context, in which your application was deployed
    • {host} - is the host where the SQL Server is running and the port of the SQL Server (e.g. localhost:1433)
    • {database} - is the database name (e.g. pubs)
    • {user} - is the user for the SQL server (e.g. sa) {password} is the password for the user (e.g. password) |
  5. After changing the server.xml file, save it and restart your Apache/Tomcat.
 

© Copyright 1996 - 2024, i-net software; All Rights Reserved.