[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Problems with tomcat on F12



I'm having problems with tomcat connecting to a mysql database

The following file works when placed in directory tests under tomcat's /usr/share/tomcat6/webapps/ROOT/tests directory

<% page language="java" contentType="text/html"%>
<% page import="java.sql.*"%>
<html><head><title>JDBC test</title></head><body>
<%
  Class.forName("com.mysql.jdbc.Driver");
  Connection conn = DriverManager.getConnection(
      "jdbc:mysql://localhost:3306/shop", "root", "password");
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery("select * from books");
  %><table border= "1"><%
  ResultSetMetaData resMetaData = rs.getMetaData();
  int nCols = resMetaData.getColumnCount();
  %><tr><%
  for (int kCol = 1; kCol <= nCols; kCol++) {
    out.print("<td><b>" + resMetaData.getColumnName(kCol) + "</b></td>");
    }
  %></tr><%
  while (rs.next()) {
    %><tr><%
    for (int kCol = 1; kCol <= nCols; kCol++) {
      out.print("<td>" + rs.getString(kCol) + "</td>");
      }
    %></tr><%
    }
  %></table><%
  conn.close();
  %>
</body></html>

and accessed as

http://localhost:8080/tests/jdbc.jsp

However, if I deploy a war file with the following web.xml file

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app id="WebApp_ID" version="2.5"
  xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
    <display-name>eshop</display-name>
    <servlet>
        <description>
        </description>
        <display-name>ShopServlet</display-name>
        <servlet-name>ShopServlet</servlet-name>
        <servlet-class>eshop.ShopServlet</servlet-class>
      <init-param>
        <param-name>base</param-name>
        <param-value>/eshop/shop</param-value>
        </init-param>
      <init-param>
        <param-name>imageURL</param-name>
        <param-value>/eshop/images/</param-value>
        </init-param>
      <init-param>
        <param-name>jdbcDriver</param-name>
        <param-value>com.mysql.jdbc.Driver</param-value>
        </init-param>
      <init-param>
        <param-name>dbURL</param-name>
        <param-value>jdbc:mysql://localhost:3306/shop</param-value>
        </init-param>
      <init-param>
        <param-name>dbUserName</param-name>
        <param-value>root</param-value>
        </init-param>
      <init-param>
        <param-name>dbPassword</param-name>
        <param-value>password</param-value>
        </init-param>
      </servlet>
    <servlet-mapping>
        <servlet-name>ShopServlet</servlet-name>
        <url-pattern>/shop/*</url-pattern>
      </servlet-mapping>
  </web-app>

I get the following error:

Could not connect to DB: No suitable driver found for

I've searched the various forums on mysql and I see this problem reported many times before, but was never able to find and answer.

Does anybody know what I'm doing wrong?

Thanks,
Paolo

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]