?
Solved

Having nightmare configuring server.xml

Posted on 2006-04-06
22
Medium Priority
?
298 Views
Last Modified: 2010-03-31
Hi,

I have a server.xml file that I need to configure to get my jsp pages fetching data from mysql database. My Server is apache/tomcat 5.5.16 and MySQL version is 5.0. The connector .jar for MySQL is in place. Now I have to configure <Context> tag in server.xml for MySQL and also for each class name has to be defined via the server.xml.

I have 23 .class files on the server and the following in my <Host> tag in server.xml

<Host name="www.nichefhgs.com" appBase="/www/virtual/mja/www.nichefhgs.com"
        unpackWARs="true" autoDeploy="true">

        <Context path="" docBase="" debug="0" reloadable="true"/>

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="web1_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>
      </Host>

Please help, it has been a nightmare for me.

N.
0
Comment
Question by:n2alexan
  • 12
  • 10
22 Comments
 
LVL 92

Expert Comment

by:objects
ID: 16397134
you could just build a war, and avoid touching server.xml all together


or in server.xml your context would look something like:

<Context path="/DBTest" docBase="DBTest"
        debug="5" reloadable="true" crossContext="true">

    <!-- maxActive: 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.
         -->

    <!-- maxIdle: Maximum number of idle dB connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->

    <!-- maxWait: 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.
         -->

    <!-- username and password: MySQL dB username and password for dB connections  -->

    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
         -->
   
    <!-- url: 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.
         -->

  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>

</Context>

taken from http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
0
 

Author Comment

by:n2alexan
ID: 16397152
even if I have a class that connects to the database and this class is used for all my sql data reading and writing I would still have to add what you have suggested.

public class Connector {
   
    /** Creates a new instance of Connector */
    public Connector() {
    }
   
    private String dbUrl = "jdbc:mysql://localhost:3306/mydatabasename";
    private String jdbcDriver = "com.mysql.jdbc.Driver";
     
    public Connection getConnection() {
       
        Connection con = null;
       
        try {
           
            Class.forName(jdbcDriver);
            con = DriverManager.getConnection(dbUrl, "someuser", "somepassword");
           
        } catch (SQLException se) {
           
            System.err.print("getConnection SQLException: " + se.toString());
           
        } catch (ClassNotFoundException cnfe) {
           
            System.err.print("getConnection ClassNotFoundException: " + cnfe.toString());
           
        }
       
        return con;
       
    }
}
0
 

Author Comment

by:n2alexan
ID: 16397157
Also, my host told me that there's no auto deployment and
each class name has to be defined via the server.xml. I have 23 .class files. What should I do about this?

Thank you for you help.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 16397160
no, to do that you would not need anything specific in your server.xml.
you'd just need to add the driver jar to your webapp
0
 
LVL 92

Expert Comment

by:objects
ID: 16397163
> each class name has to be defined via the server.xml. I have 23 .class files. What should I do about this?

not sure what they meant.
u sure they didn't mean each *context* would need to be defined?
0
 

Author Comment

by:n2alexan
ID: 16397166
how do I add the driver jar to my webapp?
0
 

Author Comment

by:n2alexan
ID: 16397183
For my questions to the host "Did I place my .class files in the correct directory? (WEB-INF/classes)"
the host replied

the host replied with this:
"there's no auto deployment each class name has to be defined via the server.xml under the virtualhost for www.nichefhgs.com"

I thought that it means that each class files must be somehow declared in server.xml.

And I am not sure how to do it?

Many thanks for help
0
 
LVL 92

Expert Comment

by:objects
ID: 16397190
either put them in <tomcat>/common/lib to make them available to all webapps

or put them in <webapp>/WEB-INF/lib
0
 
LVL 92

Expert Comment

by:objects
ID: 16397199
> "there's no auto deployment each class name has to be defined via the server.xml under the virtualhost for www.nichefhgs.com"

i think they meant each *context* has to be defined in server.xml
0
 

Author Comment

by:n2alexan
ID: 16397225
ok I have created /WEB-INF/lib directory and copied my framework/<class files> there, where framework is my package name (actually I do not have webapp directory on my server and instead I have to put everything in /www/virtual/mja directory.)
0
 

Author Comment

by:n2alexan
ID: 16397251
But it is not working
0
 
LVL 92

Expert Comment

by:objects
ID: 16397252
just jars should go in WEB-INF/lib
classes goo in WEB-INF/classes


When I say <webapp> I am referring to whatever directory your web application is in, sorry that wasn't clear
0
 

Author Comment

by:n2alexan
ID: 16397278
I have checked <tomcat>/common/lib directory and it contains mysql-connector-java-3.1.12-bin.jar which is Connector J
0
 

Author Comment

by:n2alexan
ID: 16397283
And if I understand correctly I do not need to place this file in WEB-INF/lib directory for my Web Application.
0
 
LVL 92

Expert Comment

by:objects
ID: 16397296
>  And if I understand correctly I do not need to place this file in WEB-INF/lib directory for my Web Application.

correct
0
 

Author Comment

by:n2alexan
ID: 16397402
I have just created simple jsp page (I used the correct login values for db, username and password).

==================

<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost/somedb?user=someuser;password=somepassword";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>

<html><body>

<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "", "");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM cat");

while (rs.next()) {
out.println(rs.getString("cat_name")+"<br>");
}

rs.close();
%>

</body></html>

==================

which when I call gives me this org.apache.jasper.JasperException: Exception in JSP: /testdb.jsp:13

10:
11: <%
12: Class.forName("com.mysql.jdbc.Driver").newInstance();
13: connection = DriverManager.getConnection(connectionURL, "", "");
14: statement = connection.createStatement();
15: rs = statement.executeQuery("SELECT * FROM category");
16:


Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

javax.servlet.ServletException: Access denied for user ''@'127.0.0.1' (using password: NO)
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
      org.apache.jsp.testdb_jsp._jspService(testdb_jsp.java:74)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Do you have any idea what is going on here?



0
 

Author Comment

by:n2alexan
ID: 16397403
I use the same credentials to login into phpMyAdmin
0
 

Author Comment

by:n2alexan
ID: 16397410
The main reason why I used this page to test is that it does not use any java beans.
This will eliminate that problem and just concentrate on connection.

Many many thanks for your help.
0
 
LVL 92

Expert Comment

by:objects
ID: 16397413
looks like you don't have access to mysql.
do you need to provide user/password?
0
 
LVL 92

Expert Comment

by:objects
ID: 16397755
> connection = DriverManager.getConnection(connectionURL, "", "");

supply the user/pass here

connection = DriverManager.getConnection(connectionURL, "someuser", "somepass");
0
 

Author Comment

by:n2alexan
ID: 16405260
Dear object,

You were right. I do not need anything in server.xml. My host had resolved the issue by changing persmissions for root for 127.

Thank you for your help,
N.
0
 
LVL 92

Expert Comment

by:objects
ID: 16405333
no worries :)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question