Connecting to a database from your Tomcat web app

Here's an example for MySQL which you can place in e.g. test.jsp:

<%@page language="java" import="java.sql.*" contentType="text/plain; charset=UTF-8" pageEncoding="UTF-8"%>
Class.forName( "com.mysql.jdbc.Driver" );
java.sql.Connection con = DriverManager.getConnection(
out.println( con.toString() );

The MySQL driver is pre-installed in $TOMCAT_HOME/lib so you don't need to put it in your web app's WEB-INF/lib .

PostgreSQL drivers are not pre-installed. Neither are SQLite and HSQLDB drivers.

  • Tomcat, Java, Connection, Database, web apps, MySQL, SQL
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Our Java environment

We run Tomcat application server on Oracle JVM. Tomcat is run behind Apache HTTPd front-end so we...

Which domains and subdomains can have Tomcat web apps

A domain or subdomain can have Tomcat web apps deployed if it: has hosting enabled is active,...

Before requesting deployment

It is important to test your Tomcat web apps locally before requesting their deployment. The...

Where should you upload your Tomcat web apps

Tomcat web apps should you placed directly in the DocumentRoot. For a subscription's main domain...

WAR files

WAR files must be extracted in order to be deployed. E.g. the contents of test.war should be...

Powered by WHMCompleteSolution