Tomcat / MySQL problem

Simple Tomcat / MySQL code works well on the development server (Windows) but crashes on the production server (Linux).
It finds and loads the driver, then fails to create a connection with
java.security.AccessControlException: access denied (java.net.SocketPermission localhost resolve)Driver is mysql-connector-java-3.0.14-production-bin.jar in ${catalina.home}/common/lib.
MySQL is version 3.23.58.
Tomcat version 4.1.29.
Java version 1.4.2_02.
Operating system is RedHat 9 with Plesk 7.
This looks like a Tomcat security issue but catalina.policy grants all permissions to ${catalina.home}/common/lib/-.
Granting specific permissions has made no difference:
grant codeBase "file:${catalina.home}/common/lib/mysql-connector-java-3.0.14-production-bin.jar" {
  permission java.net.SocketPermission "localhost:3306", "listen,connect,accept,resolve";
};The code is straight from the Java tutorial, presented three ways:
1. in a bean, called from a JSP
2. inline in a JSP
3. in a JAR, as an executable class
All of these work in Windows. Only No 3 works in Linux (which suggests the issue is not with Java security). Other JSP pages work fine.
I have not found a MySQL driver preinstalled on the system. I first added mysql-connector-java-3.1.10-bin.jar but this failed because it could not read charset mappings. I have
now reverted to mysql-connector-java-3.0.14-production-bin.jar. Adding the JAR in application/WEB-INF/lib does not help.
I wonder if there is a class loader issue but I cannot find any other JARs that conflict.
Could Tomcat be trying to connect on a different port? It makes no difference whether or not the port number (3306) is included in the URL.
Granting permissions for IP addresses and domain names makes no difference (so far). Besides, the error message is specific about localhost.
Can anyone help, please?
Many thanks
Robin

Spot on! I am not at all clear whether the root cause of the problem is Tomcat, MySQL, Java or whatever ... Until I understand more, everything is suspect.
I have been asking myself what can cause this Access denied / SocketPermission error?
- mis-configuration of the permission: codebase, url, port ?
- in the wrong policy file? catalina.policy or java.policy ?
- faulty installation of something?
- incompatible versions ?
The code all works well on the development machine, which runs Windows 2000. Running it on the Linux machine causes problems.
I do not have full control of the configuration of the Linux machine but I am able to restart Tomcat when needed.
Some specific questions:
I know from the stack trace which Java function is being called:
java.sql.DriverManager.getConnection()The MySQL driver is checking for socket permission when it tries to get a connection and throws:
java.security.AccessControlException: access denied (java.net.SocketPermission localhost resolve) - How do I tell what parameters are being passed to getConnection() without installing the source code?
- How do I tell for sure which policy file governs the check?
Many thanks
Robin

Similar Messages

  • How to combinate JSP+Tomcat+mysql??

    Hi,guys. My question is as the above subject.
    I have installed JDK, Tomcat, mysql, and my OS is WinXP, I am trying to develop a JSP site in my computer.
    For JDK, the commands javac, java, ...... work OK;
    For Tomcat, http://localhost:8080 works OK, meaning the cat page appears.
    For mysql, I can login, and sql statements work OK;
    And I download mysql-connector-java-3.1.8a.
    What I should do further to combinate JSP+Tomcat+mysql, so my JSP site can work? Any advice?
    I need help.
    Thanks in advance!

    Thanks,duffymo!
    As you said, I am learning more about those things.
    Actually I am trying to open a JSP webpage to show the connection JSP+Tomcat+mysql works OK.
    I copied the mysql-connector-java-3.1.8-bin.jar to ...Tomcat 5.0\common\lib,
    created a datebase, named test in MySQL, and wrote a JSP as the below:
    <%@ page contentType="text/html; charset=gb2312" %>
    <%@ page language="java" %>
    <%@ page import="com.mysql.jdbc.Driver" %>
    <%@ page import="java.sql.*" %>
    <%
    //driver
    String driverName="com.mysql.jdbc.Driver";
    //username
    String userName="test";
    //code
    String userPasswd="123";
    //database
    String dbName="test";
    //table name
    String tableName="mytab";
    //connection string
    String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection connection=DriverManager.getConnection(url);
    Statement statement = connection.createStatement();
    String sql="SELECT * FROM "+tableName;
    ResultSet rs = statement.executeQuery(sql);
    ResultSetMetaData rmeta = rs.getMetaData();
    int numColumns=rmeta.getColumnCount();
    // output
    out.print("id");
    out.print("|");
    out.print("num");
    out.print("<br>");
    while(rs.next()) {
    out.print(rs.getString(1)+" ");
    out.print("|");
    out.print(rs.getString(2));
    out.print("<br>");
    out.print("<br>");
    out.print("successful!");
    rs.close();
    statement.close();
    connection.close();
    %>
    How can I test the connection JSP+Tomcat+mysql works OK?
    Thanks again!

  • Apache webserver can't find tomcat - mod_jk problem?

    Hi
    I have recently upgraded HP-UX apache software
    FROM
    Apache webserver: 2.0.55
    Apache tomcat : 5.5.9
    TO
    Apache webserver: 2.0.55
    Apache tomcat : 5.5.9
    I have 2 tomcats running, one JVM for a daytime service and another for a nighttime service.
    So while 1 tomcat is down, the other is up, apache always running.
    However, since I have upgraded, I see the following error messages in jk.log:
    [Mon Nov 20 07:00:41 2006] [error] ajp_connection_tcp_get_message::jk_ajp_common
    .c (949): ERROR: can't receive the response message from tomcat, network problems or tomcat is down (127.0.0.1:8059), err=-232
    The tomcat in question is up - and the messages returned are 500 responses - server configuration issue.
    Get several a day.
    Basically using mod_jk to bind the tomcat installations to apache webserver.
    What is new though in mod_jk 1.2.10 is that a shared memory file is specified. I am wondering what happens to this memory that is used to load balance the workers when tomcats are bounced.
    Issues go away after a bounce of apache - but after each tomcat has been stopped once - messages start to fail intermittently after that.
    Done some googling but do not see any solutions - so here's hoping!
    Thanks.

    Noticed my deliberate mistake!
    From
    Apache 2.0.32
    Tomcat 3
    Still no joy with with this in terms of finding a solution to why the newer version of apache cannot find tomcat after it has been bounced.
    mod_jk.so version 1.2.9 introduced the shared memory for the workers, which as far as I can is the main config change in the 2 versions of apache that came from HP.
    So rolled back to the old version of apache with the new version of tomcat - and everything works fine!

  • Problem in jdbc-tomcat-mysql connection

    hi everybody
    i m in serious problem since last 15-20 days. i m trying hard to make the connection jdbc-mysql using tomcat with the help of a jsp test page but every time i am facing almost the similar probems listed below in detail:
    to make sure that the jdrivers's .jar (mysql-connector-java-3.1.7-bin.jar) available for such connections working fine i have tried the above said connection without using tomcat....which is working fine...for this i have created a dummy database with a dummy table ..and written some queries in the .java file of my code which upon running inserts the specified values in the defined(dummy) database.
    this is the confirmation that the classpath etc..are ok in regard to the mysql-connector-java-3.1.7-bin.jar
    now i have placed a copy of this .jar file in to the commons/lib directory of the tomcat web server(which is suppossed to be the place for such external jars)
    after doing so i have followed 2 methods :
    method 1st:........
    i have made aone more jar file from the following .java file....
    import javax.naming.*;
    import javax.sql.*;
    import java.sql.*;
    public class TestSQLLoad
    String user = "Not Connected";
    String pwd = "no pwd";
    int id = -1;
    public void init() {
    try{
    Context ctx = new InitialContext();
    if(ctx == null ) {
    throw new Exception("Boom - No Context");
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
    if (ds != null) {
    Connection conn = ds.getConnection();
    if(conn != null) {
    user = "Got Connection "+conn.toString();
    Statement stmt = conn.createStatement();
    String q = "select name, password, id from user";
    ResultSet rst = stmt.executeQuery(q);
    if(rst.next()) {
    user=rst.getString(1);
    pwd=rst.getString(2);
    id = rst.getInt(3);
    conn.close();
    }catch(Exception e) {
    e.printStackTrace();
    public String getUser() {
    return user;
    public String getPassword() {
    return pwd;
    public int getID()
    return id;
    after compiling it at the cmd prompt i made a .jar file from the .class of it and named it MySQLLoad.jar...then i placed it also in to the commons/lib directory where the mysql-connector-java-3.1.7-bin.jar was already placed.
    then i have changed the server.xml and web.xml files from the conf directory of the tomcat as given here:
    server.xml
    <!-- Example Server Configuration File -->
    <!-- Note that component elements are nested corresponding to their
    parent-child relationships with each other -->
    <!-- A "Server" is a singleton element that represents the entire JVM,
    which may contain one or more "Service" instances. The Server
    listens for a shutdown command on the indicated port.
    Note: A "Server" is not itself a "Container", so you may not
    define subcomponents such as "Valves" or "Loggers" at this level.
    -->
    <Server port="8005" shutdown="SHUTDOWN">
    <!-- Comment these entries out to disable JMX MBeans support used for the
    administration web application -->
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
    <!-- Global JNDI resources -->
    <GlobalNamingResources>
    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    <!-- Editable user database that can also be used by
    UserDatabaseRealm to authenticate users -->
    <Resource name="UserDatabase" auth="Container"
    type="org.apache.catalina.UserDatabase"
    description="User database that can be updated and saved"
    factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
    pathname="conf/tomcat-users.xml" />
    </GlobalNamingResources>
    <!-- A "Service" is a collection of one or more "Connectors" that share
    a single "Container" (and therefore the web applications visible
    within that Container). Normally, that Container is an "Engine",
    but this is not required.
    Note: A "Service" is not itself a "Container", so you may not
    define subcomponents such as "Valves" or "Loggers" at this level.
    -->
    <!-- Define the Tomcat Stand-Alone Service -->
    <Service name="Catalina">
    <!-- A "Connector" represents an endpoint by which requests are received
    and responses are returned. Each Connector passes requests on to the
    associated "Container" (normally an Engine) for processing.
    By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
    You can also enable an SSL HTTP/1.1 Connector on port 8443 by
    following the instructions below and uncommenting the second Connector
    entry. SSL support requires the following steps (see the SSL Config
    HOWTO in the Tomcat 5 documentation bundle for more detailed
    instructions):
    * If your JDK version 1.3 or prior, download and install JSSE 1.0.2 or
    later, and put the JAR files into "$JAVA_HOME/jre/lib/ext".
    * Execute:
    %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
    $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (Unix)
    with a password value of "changeit" for both the certificate and
    the keystore itself.
    By default, DNS lookups are enabled when a web application calls
    request.getRemoteHost(). This can have an adverse impact on
    performance, so you can disable it by setting the
    "enableLookups" attribute to "false". When DNS lookups are disabled,
    request.getRemoteHost() will return the String version of the
    IP address of the remote client.
    -->
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector
    port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />
    <!-- Note : To disable connection timeouts, set connectionTimeout value
    to 0 -->
         <!-- Note : To use gzip compression you could set the following properties :
                   compression="on"
                   compressionMinSize="2048"
                   noCompressionUserAgents="gozilla, traviata"
                   compressableMimeType="text/html,text/xml"
         -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
    <!--
    <Connector port="8443"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" disableUploadTimeout="true"
    acceptCount="100" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS" />
    -->
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009"
    enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
    <!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
    <!-- See proxy documentation for more information about using this. -->
    <!--
    <Connector port="8082"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" acceptCount="100" connectionTimeout="20000"
    proxyPort="80" disableUploadTimeout="true" />
    -->
    <!-- An Engine represents the entry point (within Catalina) that processes
    every request. The Engine implementation for Tomcat stand alone
    analyzes the HTTP headers included with the request, and passes them
    on to the appropriate Host (virtual host). -->
    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <!-- Define the top level container in our container hierarchy -->
    <Engine name="Catalina" defaultHost="localhost">
    <!-- The request dumper valve dumps useful debugging information about
    the request headers and cookies that were received, and the response
    headers and cookies that were sent, for all requests received by
    this instance of Tomcat. If you care only about requests to a
    particular virtual host, or a particular application, nest this
    element inside the corresponding <Host> or <Context> entry instead.
    For a similar mechanism that is portable to all Servlet 2.4
    containers, check out the "RequestDumperFilter" Filter in the
    example application (the source for this filter may be found in
    "$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").
    Request dumping is disabled by default. Uncomment the following
    element to enable it. -->
    <!--
    <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
    -->
    <!-- Because this Realm is here, an instance will be shared globally -->
    <!-- This Realm uses the UserDatabase configured in the global JNDI
    resources under the key "UserDatabase". Any edits
    that are performed against this UserDatabase are immediately
    available for use by the Realm. -->
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
    resourceName="UserDatabase"/>
    <!-- Comment out the old realm but leave here for now in case we
    need to go back quickly -->
    <!--
    <Realm className="org.apache.catalina.realm.MemoryRealm" />
    -->
    <!-- Replace the above Realm with one of the following to get a Realm
    stored in a database and accessed via JDBC -->
    <!--
    <Realm className="org.apache.catalina.realm.JDBCRealm"
    driverName="org.gjt.mm.mysql.Driver"
    connectionURL="jdbc:mysql://localhost/authority"
    connectionName="test" connectionPassword="test"
    userTable="users" userNameCol="user_name" userCredCol="user_pass"
    userRoleTable="user_roles" roleNameCol="role_name" />
    -->
    <!--
    <Realm className="org.apache.catalina.realm.JDBCRealm"
    driverName="oracle.jdbc.driver.OracleDriver"
    connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
    connectionName="scott" connectionPassword="tiger"
    userTable="users" userNameCol="user_name" userCredCol="user_pass"
    userRoleTable="user_roles" roleNameCol="role_name" />
    -->
    <!--
    <Realm className="org.apache.catalina.realm.JDBCRealm"
    driverName="sun.jdbc.odbc.JdbcOdbcDriver"
    connectionURL="jdbc:odbc:CATALINA"
    userTable="users" userNameCol="user_name" userCredCol="user_pass"
    userRoleTable="user_roles" roleNameCol="role_name" />
    -->
    <!-- Define the default virtual host
    Note: XML Schema validation will not work with Xerces 2.2.
    -->
    <Host name="localhost" appBase="webapps"
    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
    <!-- Defines a cluster for this node,
    By defining this element, means that every manager will be changed.
    So when running a cluster, only make sure that you have webapps in there
    that need to be clustered and remove the other ones.
    A cluster has the following parameters:
    className = the fully qualified name of the cluster class
    name = a descriptive name for your cluster, can be anything
    mcastAddr = the multicast address, has to be the same for all the nodes
    mcastPort = the multicast port, has to be the same for all the nodes
    mcastBindAddr = bind the multicast socket to a specific address
    mcastTTL = the multicast TTL if you want to limit your broadcast
    mcastSoTimeout = the multicast readtimeout
    mcastFrequency = the number of milliseconds in between sending a "I'm alive" heartbeat
    mcastDropTime = the number a milliseconds before a node is considered "dead" if no heartbeat is received
    tcpThreadCount = the number of threads to handle incoming replication requests, optimal would be the same amount of threads as nodes
    tcpListenAddress = the listen address (bind address) for TCP cluster request on this host,
    in case of multiple ethernet cards.
    auto means that address becomes
    InetAddress.getLocalHost().getHostAddress()
    tcpListenPort = the tcp listen port
    tcpSelectorTimeout = the timeout (ms) for the Selector.select() method in case the OS
    has a wakup bug in java.nio. Set to 0 for no timeout
    printToScreen = true means that managers will also print to std.out
    expireSessionsOnShutdown = true means that
    useDirtyFlag = true means that we only replicate a session after setAttribute,removeAttribute has been called.
    false means to replicate the session after each request.
    false means that replication would work for the following piece of code: (only for SimpleTcpReplicationManager)
    <%
    HashMap map = (HashMap)session.getAttribute("map");
    map.put("key","value");
    %>
    replicationMode = can be either 'pooled', 'synchronous' or 'asynchronous'.
    * Pooled means that the replication happens using several sockets in a synchronous way. Ie, the data gets replicated, then the request return. This is the same as the 'synchronous' setting except it uses a pool of sockets, hence it is multithreaded. This is the fastest and safest configuration. To use this, also increase the nr of tcp threads that you have dealing with replication.
    * Synchronous means that the thread that executes the request, is also the
    thread the replicates the data to the other nodes, and will not return until all
    nodes have received the information.
    * Asynchronous means that there is a specific 'sender' thread for each cluster node,
    so the request thread will queue the replication request into a "smart" queue,
    and then return to the client.
    The "smart" queue is a queue where when a session is added to the queue, and the same session
    already exists in the queue from a previous request, that session will be replaced
    in the queue instead of replicating two requests. This almost never happens, unless there is a
    large network delay.
    -->
    <!--
    When configuring for clustering, you also add in a valve to catch all the requests
    coming in, at the end of the request, the session may or may not be replicated.
    A session is replicated if and only if all the conditions are met:
    1. useDirtyFlag is true or setAttribute or removeAttribute has been called AND
    2. a session exists (has been created)
    3. the request is not trapped by the "filter" attribute
    The filter attribute is to filter out requests that could not modify the session,
    hence we don't replicate the session after the end of this request.
    The filter is negative, ie, anything you put in the filter, you mean to filter out,
    ie, no replication will be done on requests that match one of the filters.
    The filter attribute is delimited by ;, so you can't escape out ; even if you wanted to.
    filter=".*\.gif;.*\.js;" means that we will not replicate the session after requests with the URI
    ending with .gif and .js are intercepted.
    The deployer element can be used to deploy apps cluster wide.
    Currently the deployment only deploys/undeploys to working members in the cluster
    so no WARs are copied upons startup of a broken node.
    The deployer watches a directory (watchDir) for WAR files when watchEnabled="true"
    When a new war file is added the war gets deployed to the local instance,
    and then deployed to the other instances in the cluster.
    When a war file is deleted from the watchDir the war is undeployed locally
    and cluster wide
    -->
    <!--
    <Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
    managerClassName="org.apache.catalina.cluster.session.DeltaManager"
    expireSessionsOnShutdown="false"
    useDirtyFlag="true"
    notifyListenersOnReplication="true">
    <Membership
    className="org.apache.catalina.cluster.mcast.McastService"
    mcastAddr="228.0.0.4"
    mcastPort="45564"
    mcastFrequency="500"
    mcastDropTime="3000"/>
    <Receiver
    className="org.apache.catalina.cluster.tcp.ReplicationListener"
    tcpListenAddress="auto"
    tcpListenPort="4001"
    tcpSelectorTimeout="100"
    tcpThreadCount="6"/>
    <Sender
    className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
    replicationMode="pooled"
    ackTimeout="15000"/>
    <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
    filter=".*\.gif;.*\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"/>
    <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
    tempDir="/tmp/war-temp/"
    deployDir="/tmp/war-deploy/"
    watchDir="/tmp/war-listen/"
    watchEnabled="false"/>
    </Cluster>
    -->
    <!-- Normally, users must authenticate themselves to each web app
    individually. Uncomment the following entry if you would like
    a user to be authenticated the first time they encounter a
    resource protected by a security constraint, and then have that
    user identity maintained across all web applications contained
    in this virtual host. -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->
    <!-- Access log processes all requests for this virtual host. By
    default, log files are created in the "logs" directory relative to
    $CATALINA_HOME. If you wish, you can specify a different
    directory with the "directory" attribute. Specify either a relative
    (to $CATALINA_HOME) or absolute path to the desired directory.
    -->
    <!--
    <Valve className="org.apache.catalina.valves.AccessLogValve"
    directory="logs" prefix="localhost_access_log." suffix=".txt"
    pattern="common" resolveHosts="false"/>
    -->
    <!-- Access log processes all requests for this virtual host. By
    default, log files are created in the "logs" directory relative to
    $CATALINA_HOME. If you wish, you can specify a different
    directory with the "directory" attribute. Specify either a relative
    (to $CATALINA_HOME) or absolute path to the desired directory.
    This access log implementation is optimized for maximum performance,
    but is hardcoded to support only the "common" and "combined" patterns.
    -->
    <!--
    <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
    directory="logs" prefix="localhost_access_log." suffix=".txt"
    pattern="common" resolveHosts="false"/>
    -->
    <Context path="/testdb" docBase="TOMCAT_HOME/webapps/tomcat-docs/testdb"
    debug="5" reloadable="true" crossContext="true" >
    <Logger className="org.apache.catalina.logger.FileLogger"
    prefix="localhost_DBTest_log." suffix=".txt"
    timestamp="true"/>
    <Resource name="jdbc/TestDB"
    auth="Container"
    type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/TestDB">
    <parameter>
    <name>factory</name>
    <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <!-- Maximum number of dB connections in pool. Make sure you
    configure your mysqld max_connections large enough to handle
    all of your db connections. Set to 0 for no limit.
    -->
    <parameter>
    <name>maxActive</name>
    <value>10</value>
    </parameter>
    <!-- Maximum number of idle dB connections to retain in pool.
    Set to 0 for no limit.
    -->
    <parameter>
    <name>maxIdle</name>
    <value>5</value>
    </parameter>
    <!-- Maximum time to wait for a dB connection to become available
    in ms, in this example 10 seconds. An Exception is thrown if
    this timeout is exceeded. Set to -1 to wait indefinitely.
    -->
    <parameter>
    <name>maxWait</name>
    <value>10000</value>
    </parameter>
    <!-- MySQL dB username and password for dB connections -->
    <parameter>
    <name>username</name>
    <value>root</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>mysql</value>
    </parameter>
    <!-- Class name for mm.mysql JDBC driver -->
    <parameter>
    <name>driverClassName</name>
    <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <!-- The JDBC connection url for connecting to your MySQL dB.
    The autoReconnect=true argument to the url makes sure that the
    mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
    connection. mysqld by default closes idle connections after 8 hours.
    -->
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost/testdb?autoReconnect=true</value>
    </parameter>
    </ResourceParams>
    </Context>
    </Host>
    </Engine>
    </Service>
    </Server>
    and the other xml file i.e
    web.xml is here:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app 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_4.xsd"
    version="2.4">
    <!-- ======================== Introduction ============================== -->
    <!-- This document defines default values for all web applications -->
    <!-- loaded into this instance of Tomcat. As each application is -->
    <!-- deployed, this file is processed, followed by the -->
    <!-- "/WEB-INF/web.xml" deployment descriptor from your own -->
    <!-- applications. -->
    <!-- -->
    <!-- WARNING: Do not configure application-specific resources here! -->
    <!-- They should go in the "/WEB-INF/web.xml" file in your application. -->
    <!-- ================== Built In Servlet Definitions ==================== -->
    <!-- The default servlet for all web applications, that serves static -->
    <!-- resources. It processes all requests that are not mapped to other -->
    <!-- servlets with servlet mappings (defined either here or in your own -->
    <!-- web.xml file. This servlet supports the following initialization -->
    <!-- parameters (default values are in square brackets): -->
    <!-- -->
    <!-- debug Debugging detail level for messages logged -->
    <!-- by this servlet. [0] -->
    <!-- -->
    <!-- input Input buffer size (in bytes) when reading -->
    <!-- resources to be served. [2048] -->
    <!-- -->
    <!-- listings Should directory listings be produced if there -->
    <!-- is no welcome file in this directory? [true] -->
    <!-- -->
    <!-- output Output buffer size (in bytes) when writing -->
    <!-- resources to be served. [2048] -->
    <!-- -->
    <!-- readonly Is this context "read only", so HTTP -->
    <!-- commands like PUT and DELETE are -->
    <!-- rejected? [true] -->
    <!-- -->
    <!-- readmeFile File name to display with the directory -->
    <!-- contents. [null] -->
    <!-- -->
    <!-- For directory listing customization. Checks localXsltFile, then -->
    <!-- globalXsltFile, then defaults to original behavior. -->
    <!-- -->
    <!-- localXsltFile Make directory listings an XML doc and -->
    <!-- pass the result to this style sheet residing -->
    <!-- in that directory. This overrides -->
    <!-- globalXsltFile[null] -->
    <!-- -->
    <!-- globalXsltFile Site wide configuration version of -->
    <!-- localXsltFile This argument is expected -->
    <!-- to be a physical file. [null] -->
    <!-- -->
    <!-- -->
    <servlet>
    <servlet-name>default</servlet-name>
    <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/TestDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
    <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
    </init-param>
    <init-param>
    <param-name>listings</param-name>
    <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- The "invoker" servlet, which executes anonymous servlet classes -->
    <!-- that have not been defined in a web.xml file. Traditionally, this -->
    <!-- servlet is mapped to the URL pattern "/servlet/*", but you can map -->
    <!-- it to other patterns as well. The extra path info portion of such a -->
    <!-- request must be the fully qualified class name of a Java class that -->
    <!-- implements Servlet (or extends HttpServlet), or the servlet name -->
    <!-- of an existing servlet definition. This servlet supports the -->
    <!-- following initialization parameters (default values are in square -->
    <!-- brackets): -->
    <!-- -->
    <!-- debug Debugging detail level for messages logged -->
    <!-- by this servlet. [0] -->
    <servlet>
    <servlet-name>invoker</servlet-name>
    <servlet-class>
    org.apache.catalina.servlets.InvokerServlet
    </servlet-class>
    <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <!-- The JSP page compiler and execution servlet, which is the mechanism -->
    <!-- used by Tomcat to support JSP pages. Traditionally, this servlet -->
    <!-- is mapped to the URL pattern "*.jsp". This servlet supports the -->
    <!-- following initialization parameters (default values are in square -->
    <!-- brackets): -->
    <!-- -->
    <!-- checkInterval If development is false and checkInterval is -->
    <!-- greater than zero, background compilations are -->
    <!-- enabled. checkInterval is the time in seconds -->
    <!-- between checks to see if a JSP page needs to -->
    <!--

    Look at the URl below:
    How to connect to Microsoft SQL server with Type 4 JDBC driver
    http://www.java-tips.org/content/view/615/29/

  • JSP + JDBC + MySql Problem (Tomcat 4.1)

    I'm completely helpless... whenever I try to retrieve stuff from the db (using a jsp page), I get errors that don't even make sense.
    out.println(stmt.executeQuery("SELECT * FROM newsTbl WHERE articleID = 1").getString("articleTitle"));if I try doing the above, I get a "ServletException : Before start of result set" error that supposedly occurred at this line of the generated servlet:
    if (pageContext != null) pageContext.handlePageException(t);---------------
    If i try this:
    ResultSet rsSec = stmt.executeQuery("SELECT * FROM newsSecTbl");
    rsSec.beforeFirst();  //<-- Even if I don't have this line the result does not change
      out.println(rsSec.next());
      while (rsSec.next()) { ... }I the while loop is never initiated, because rsSec.next() is false... kind of weird if you ask me, I even put two entries into the table to make sure the cursor wasnt at the first record and saying there was no second one (which would have been right if there were only one record).
    I would be very grateful if someone could help me out with this. I've never done any db programming with Java yet, so I dont have a clue what Im doing. By the way, I'm using MySql (indicated in the title) and the server was running and available when I ran the above code.
    Cheers,
    Tom

    You can't do this:
    out.println(stmt.executeQuery("SELECT * FROM newsTbl WHERE articleID = 1").getString("articleTitle"));The ResultSet you get back is a database cursor that doesn't point to the first row yet. The correct idiom is:
    String sql = "SELECT * FROM newsTbl WHERE articleID = 1";
    ResultSet result = stmt.executeQuery(sql);
    String articleTitle = "";
    while (result.next())
       title = result.getString("articleTitle");
    result.close();
    stmt.close();If you've never done DB programming before, I'd recommend that you click on the Tutorials link to the left and go through the JDBC tutorial carefully. You'll save yourself a lot of grief.
    Another good idea would be to separate out all your database code into at least one separate object, independent of the servlet. That way you can test and develop it off to the side until it's 100% solid. Then your servlet can simply instantiate one and use it. All your problems from that point forward will be servlet issues, because you'll know that your database code is working. - MOD
    See if that works better. - MOD

  • JAVA with MYSQL problem

    i am using jdk1.6.0_02,apache tomcat 5.5.23 ,mysql integrated with redhat linux EE 4 and.mysql connector java 5.0.7.bin.jar.
    look at the the following java program
    import java.sql.*;
    public class TestMysql
    public static void main(String args[])
    try
    String driver = "com.mysql.jdbc.Driver";
    Class.forName( driver );
    String url = "jdbc:mysql://localhost/test";
    DriverManager.getConnection( url, "root", "mysql" );
    catch( Exception x )
    {      x.printStackTrace();
    i got the following exception
    java.sql.SQLException: Access denied for user 'root'@'localhost.localdomain' (us *** password:
    YES)
    at com.mysql.jdbc.SQLError.createSQLException(java.lang.String, java.lang.Str ***, int)
    (Unknown Source)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(int) (Unknown Source)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket() (Unknown Source)
    at com.mysql.jdbc.MysqlIO.secureAuth411(com.mysql.jdbc.Buffer, int, java.lang .String,
    java.lang.String, java.lang.String, boolean) (Unknown Source)
    at com.mysql.jdbc.MysqlIO.doHandshake(java.lang.String, java.lang.String, jav a.lang.String)
    (Unknown Source)
    at com.mysql.jdbc.Connection.createNewIO(boolean) (Unknown Source)
    at com.mysql.jdbc.Connection.Connection(java.lang.String, int, java.util.Prop erties,
    java.lang.String, java.lang.String) (Unknown Source)
    at com.mysql.jdbc.NonRegisteringDriver.connect(java.lang.String, java.util.Pr operties)
    (Unknown Source)
    at java.sql.DriverManager.getConnection(java.lang.String, java.util.Propertie s)
    (/usr/lib/libgcj.so.5.0.0)
    at java.sql.DriverManager.getConnection(java.lang.String, java.lang.String, j
    ava.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at Connect.main(java.lang.String[]) (Unknown Source)
    access denied problem. but the user name and password are correct. i can login to mysql by using
    the same username and password.
    but when connecting through java , i can't ? what is the problem?
    can u help me.?
    actually i am working in JSP. and when i got this problem, i created a small java program for testing.
    here i am submitting the java program.

    friend please put your code inside
       // your code goes here  it will more readable and other can solve it better.
    ==================
    and your problem tells that you must set access permission inside
    mySQL server.
    or try with creating new User with password.
    EnJOY.
    Ghanshyam
    Edited by: Ghanshyam on Sep 28, 2007 4:13 PM

  • JDBC/MySQL Problem

    Hello, I'm getting this error when trying to make a connection with MySQL:
    Internal Servlet Error:
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    C:\tomcat\work\localhost_8080\_0002fdb_0002ejspdb_jsp_10.java:62: Undefined variable or class name: DriverManager
         conn = DriverManager.getConnection("jdbc:mysql:numbers", "username", "password");
         ^
    1 error, 1 warning
         at org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
         at org.apache.jasper.servlet.JspServlet.doLoadJSP(JspServlet.java:612)
         at org.apache.jasper.servlet.JasperLoader12.loadJSP(JasperLoader12.java:146)
         at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:542)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:258)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:268)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
         at org.apache.tomcat.core.Handler.service(Handler.java:287)
         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
         at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
         at java.lang.Thread.run(Thread.java:536)
    Here's the code I'm using:
    <%
         Class.forName("org.gjt.mm.mysql.Driver").newInstance();
         java.sql.Connection conn;
         conn = DriverManager.getConnection("jdbc:mysql:numbers", "username", "password");
    %>
    If anyone knows how to fix this, I'd appreciate any help!

    Hi,
    Three things:
    1. I presume numbers refers to the prot you are accesaing mysql - i tend to use default 3306.
    2. If there are problems recognising DriverManagaer are you importing java.sql.*; I'm sure you are.
    3. I think the sun.tools.javac.Main error relates to the tools version that you are using, although I would not guarantee this. The tools.jar in later versions of tomcat is twice the size of earlier versions and you have to ensure this is the version that your application is checking for. A quick test for this is to put the newer version(size 74k) into WEB-INF \lib directory where an application looks first for complied java files.
    best,
    kev
    ps If I'm wrong completely, let me know as I am watching this topic

  • JSP/Tomcat/MySQL

    Hello JSP developers!
    I have a problem trying to connect to MySQL database when I am doing a JSP or a servlet. I think the problem has to be with Tomcat, because when I do a java application with a database connection works perfectly, so there must be Tomcat.
    I am working with Java j2sdk1.4.0 and Netbean as my IDE. When I compile the JSP under the IDE does not give me any errors but when I try to see the result with Tomcat 4.0 does not seem to recognize the mm.mysql driver and gives me the following errors:
    Generated servlet error:
    D:\Apache Tomcat 4.0\work\localhost\_\JspMySQL$jsp.java:75: Class org.apache.jsp.Connection not found.
    Generated servlet error:
    D:\Apache Tomcat 4.0\work\localhost\_\JspMySQL$jsp.java:76: Class org.apache.jsp.ResultSet not found.
         ResultSet results;
    It gives me more errors, related to the connection. If you are willing to help me I can send you the exception report that Tomcat generates.
    I would really appreciate if you help me about this issue, because I am beginnig to get frustated.
    Thanks!!!!

    It appears that your JspMySQL.jsp does not import the java.sql package. Try adding the following line at the top of the JSP:
    <%@ page import="java.sql.*" %>

  • Struts, hibernate, mysql problem

    I am using eclipse, struts, hibernate, mysql, tomcat to run my web application. When I try to run more than one application that using hibernate, then all the application will hang. I am only able to run one application at a time and keep changing the host in server.xml if I want to run other application that use hibernate.
    This problem occur only when I run more than one application that using hibernate. So is anyone know why does this happen??? help plx..........

    http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch13.html

  • Servlet plus mysql problem

    Well... Using Tomcat 557 and MySQL 411 I have a problem. I load a Driver (MySQL Connector/J) and create a connection object in servlet's init procedure. All woks fine. I stop Mysql and reload the servlet, nothing can be seen on a browser window - as it should be. When I start MySQL again - it cannot read from database - as if mysql were down. It works again if I reload the context, but not otherwise.
    Is there some way to correct this problem?
    There is also another peculiarity when using Mozilla Firefox 1.0.4. When I make a servlet that saves something to a file, it does it three times. Same happens with database systems. When I read from a database, it does it three times. Using MSIE or Opera, reading or writing is done once.
    -poj

    Hi! And thanks for the answer.
    I still don't understand.
    Connection object is alive in the servlet, because it is a global attribute of the servlet and servlet is alive.
    Am I right when I think that servlet does not do it's init method again until servlet stops. If so, connection object, created in init, should be alive although database is down.
    Connection object seems to loose database when database is temporarily down meanwhile you try to read from database. Connection does not nullify. All works fine after restarting database if there is no action to database when it is down.
    I have not tested system when using datasource and pooling with tomcat servlet.xml, but creating connections in init method seems to have a problem.
    Can anyone find a way to correct my problem.
    And the Firefox problem. There is no javascript and this peculiar three times loading/writing to a file happens with Firefox.
    -poj

  • Tomcat + mysql servlet

    Hi all, I've got some problems to access mysql database while running a servlet with tomcat...can anyone help me?

    Perhaps. What are the problems? Can you post the code that isn't working?

  • Tomcat config problem: jsp can't find a bean class

    I've been working within a JSP/Javabeans/JDBC/MySQL architecture with Windows XP and Websphere. So far everything works perfectly. Now I need to get the same project and make it run with a Tomcat server.
    I've already set the Tomcat server but its not working properly. I have a problem when a jsp tries to access any class inside my project's package.
    For example, when I make the next call:
    <jsp:useBean id="ctrl" class="myPack.myBean" scope="page"/>
    I get an error saying:
    Error: 500
    Location: /myproj/login.jsp
    Internal Servlet Error:
    org.apache.jasper.JasperException: Unable to compile C:\Program Files\jakarta-tomcat-3.3.1\work\DEFAULT\myproj\login_1.java:64: Class myPack.myBean not found.
    myPack.myBean ctrl = null;
    ^
    I believe that my problem cames when setting the Tomcat environment. So far what I have done is:
    * install j2sdk-1.3.1.03
    * install jakarta-tomcat-3.3.1
    * install mysql-max-3.23.51-win
    * set the environment variable JAVA_HOME
    * set the environment variable TOMCAT_HOME
    * set the environment variable MYSQL_HOME
    * add the %JAVA_HOME%\bin to the PATH
    * create 'myproj' directory inside TOMCAT_HOME\webapps
    * create into 'myproj' the subdirectory WEB-INF\classes and copy into it the jar file with my java classes (myPack.jar).
    * copy into TOMCAT_HOME\lib\apps the JDBC driver for MySQL.
    * copy my project files (jsp, html, images, etc.) and its structure into 'myproj' directory.
    I haven't include anything into the CLASSPATH because so far I've read that Tomcat will automatically include all the classes that are inside the directories TOMCAT_HOME\myproj\WEB-INF\classes and TOMCAT_HOME\lib\apps.
    I really don't have a clue about what I'm doing wrong. I'd apreciate if anyone can help me out with this one ;) ... I thank you in advance!

    Hi, it's me again!.
    Since nobody replied to me I'm replying myself :D
    Ok, seriously is just to let you know that I have solved my problem and I would like to tell you how I solved it ... somebody might be doing the same mistake than I was doing and could found this helpful. I just forgot to mention that I was using Tomcat 3.3.
    Well, first of all let me tell you that there was nothing wrong with the previous configuration that I post in my first message. Everything is ok except that in the TOMCAT_HOME\webapps\myproj\WEB-INF\classes directory I was putting my classes as a jar file, so I deleted it and instead I put the directory myPack with its unpacked class files. THIS SOLVED MY PROBLEM!!!
    First I was trying to do some complicated things editing bat and xml files, but as a matter of fact I found it's quite simple. Furthermore, I was really surprised by the performance of Tomcat. I'm relly happy for that !! ;)
    Hope it works for you,
    Ernesto

  • Tomcat - MySQL - Cannot create resource instance

    I keep getting an error when trying to lookup my JNDI name. I know that this name is bound to a Context because I can list the bindings
    Context initCtx = new InitialContext();
    NamingEnumeration enum = initCtx.listBindings("java:comp/env/jdbc");
    while (enum.hasMoreElements()) {
    System.out.println(enum.nextElement().toString());
    And sure enough the name of my database I added through the console appears. However, I keep getting this error:
    javax.naming.NamingException: Cannot create resource instance
    on this second line of code
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/ArgonautDB");
    My MySQL Connector jar file is in $CATALINA_HOME/common/lib and I believe my server.xml settings are correct because I added this Data Source to the context through the console and the web.xml file should be simple...nevertheless I still get this error.
    Any suggestions on where I else I can turn. Pulling my precious few last hairs out here....

    Thank you very much. That did the trick. Actually what did the trick was to reinstall tomcat with the standard installation, NOT the LE installation which doesn't include the dbcp jar files needed for connecting to a database - but you were right about missing those.
    I was dissapointed in Tomcat's documentation of this issue. I would have thought that something that has to have caused other developers problems like this would have been documented somewhere more pronounced (if at all) on Tomcat's site.
    For those other newbies out there who don't want to pull out your hair...here is a summary of the steps I took to remedy this problem.
    1) Install the latest version of Tomcat. Do NOT install the LE version, it does not include the neccessary library files to connect to a database (commons-dbcp.jar and commons-pool.jar).
    2) Download the latest mysql connector library from http://www.mysql.com/downloads/mysqlcc.html. Once you have extracted the tar file, there will be some directories, a README file, a couple other text files and a jar file named mysql-connector-java-VERSION-stable-bin.jar. Move the mysql-connector-java-VERSION-stable-bin.jar file to $CATALINA_HOME/common/lib.
    3) Follow the instructions on http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
    to create a test database, a test jsp file and a test class to access the database.

  • Tomcat deployment problems

    Hi,
    I have an application developed in JSC2_1 and migrated to VWP/NetBeans which I can run nicely on Sun Java Application Server 9.1. But I am trying to deploy it on tomcat server (5.5.17.,5.5.20) over few weeks. I even assembled tomcat server 6.0.14 and added jstl.jar, jsf-api.jar, jsf-impl.jar and tools.jar (from sun java jdk1.6.0_01) to the common library. Initially I got errors which I rectified. Now if I browse with mozilla firefox I see two panels and images and buttons are not loaded. If I use IE7 I find nothing. Log files do not show any error at all...Can anyone help with these deployment problems with tomcat??
    thanks in advance.
    dr. am mohan rao

    I have deployed my JSC 2.1 app to Tomcat 5.5.17 servers.
    My app is running on XP Pro (development server) and WIndows 2000 Server (deployment).
    I'm using MySQL as the database server.
    Did you export your WAR file as J2EE 1.4?
    Here are some links that might help:
    http://forum.java.sun.com/thread.jspa?threadID=5101183
    http://blogs.sun.com/david/entry/defining_java_studio_creator_2
    http://blogs.sun.com/winston/entry/redploying_to_tomcat

  • Data Sources (Tomcat) - mysql

    I tried setting up a Data Source in Tomcat to use a mysql driver, but couldn't get it to work (my Servet wasn't able to find it using a context lookup). I got told by someone that Tomcat had a problem with Data Sources.
    So I placed the mm.mysql.jar file into Tomcat's /common/lib/ and am now using the drivers directly like this;
    ClassLoader cl = this.getClass().getClassLoader();
    Class.forName("org.gjt.mm.mysql.Driver", true, cl).newInstance();
    conn = DriverManager.getConnection("jdbc:mysql://xxx.xxx.no/dbname?user=xxx&password=xxxx");It works fine,
    but I'm wondering if this will cause problems for me later? What about connection pooling etc. that I had to specify when setting up the data source in Tomcat.

    PROGRESS !!
    Initial problem
    To set up a connection with DataSource by following
    JWSDP-1.0 tutorial on Servlet's
    I set up a connection with DriverManager by following
    http://www-106.ibm.com/developerworks/java/library/j-banner/?dwzone=java
    I set up a connection with DataSource by following
    -- TOMCAT 4.1.12 > DOCUMENTATION > JNDI DataSource Howto
    My guessing thought is that the root cause might be a mysql-configuration theme ..
    for example, to configure
    "javauser@localhost identified by 'javadude' "
    actually GIVES acces,but if you try
    c:>mysql -u javauser -pjavadude
    I get denied acces ..!?

Maybe you are looking for

  • Jdeveloper 10.1.2.1.0 not working with oracle 8.1.7.4 database

    I migrated my java application using BC4j from Jdeveloper 9.0.3.4 to Jdeveloper 10.1.2.1.0. When I run my BC4j model it runs fine but when I execute the view object using BC4jContext in my action code I am getting following error: Error Message: JBO-

  • Where can I find all the songs under Play More Like This?

    I accidentally made another station that I already had, I was listening and found a song that I liked. I listed it under Play More Like This, after I noticed I had recreated the same station I deleted the newer station. As I looked for the song this

  • Hyperlink in auto respond text

    When you create text in an auto respond message (in preferences, rules, etc), is there a way to link a word ( you know,make it blue ) in the text that will, when clicked, go to a specific web page? thanks bl

  • Fireworks hotspots in Internet Explorer 7

    G'day Guys Just need a little help. I'm trialling fireworks CS3 and I'm trying to create a link off a text graphic using a hotspot: 1. Create the text 2. Right mouse button on the text, insert hotspot 3. insert the name of the page to link to in Link

  • How to tell what OSX I have, while booted into BootCamp

    Hello everybody.  I'm currently booted into my Windows BootCamp partition, but have read access to the OSX partition.  How can I tell what version of OSX I have while staying booted into my BootCamp Windows session.  Is there a file I can look at on