How to create a JDBC Data Source with Tomcat 5 to connect to MS SQL Server
- Copy the driver jar file to $CATALINA_HOME/common/lib/.
- Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to $CATALINA_HOME/conf/server.xml.
- 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 & --> <parameter> <name>url</name> <value>jdbc:inetdae7:{host}?database={database}</value> </parameter> </ResourceParams> </Context>
- 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) |
- After changing the server.xml file, save it and restart your Apache/Tomcat.