What you are describing is not within the tomcat instance. Tomcat is a "servlet" engine. Every class you write within a webapp gets rewritten into the tomcat "master" servlet when its initialized (look in the work folder if you want proof) and has to operate within the "master" servlet instance. So, you really can't run a standalone class through it's main method within the Tomcat context. You would have to create a servlet that calls a public method of your test class in order to test your connection pool.

Also - if you want to provide jdbc connectors to any or all of your webapps, put the connectors in the common/lib folder.

Hope that helps a little...
Brian Brewer

Kawthar Bt M Sulaiman wrote:

aaaahhhh..... I put my classes under
%CATALINA_HOME%\webapps\ROOT\WEB-INF\classes\com\maxis\test\TestConnection.class
I have my tomcat up and running when I ran java
com.maxis.test.TestConnection.
Isn't this "class within Tomcat"? How do I run my application without
depending
on servlet/jsp?


Thanks,
--Kawthar



[EMAIL PROTECTED] 25/03/2004 04:04:51 PM >>>


Kawthar,

From what I understand the context is not available from outside
Tomcat. If
you are running this from an IDE or command line you are in a separate
JVM
form Tomcat. You have to be trying your code from a servlet, jsp or
class
within Tomcat to use the context.

Doug

----- Original Message ----- From: "Kawthar Bt M Sulaiman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 25, 2004 2:58 AM
Subject: Re: JDBC/mySQL problem.





Doug,

I created a test stand-alone application: TestConnection.java
Inside theis class, it has
public static void main(Strig[] args)
{
  DatabaseOperation op = DatabaseOperation.newInstance();
  op.selectOperation(....)
  ...
}

When DatabaseOperation is initialized, that's when it get the
connection.
The line where I get new InitialContext() is when the error was
thrown.
So I'm not sure when actually the "driverClassName" inside


server.xml


is
being called.

Thanks,
--Kawthar



[EMAIL PROTECTED] 25/03/2004 03:33:40 PM >>>


Kawthar,

Please clarify what you mean by "inside the main()".

Doug

----- Original Message ----- From: "Kawthar Bt M Sulaiman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 24, 2004 9:37 PM
Subject: RE: JDBC/mySQL problem.





Hi folks,

Sorry to bring back this issue.... I still cannot make my


connection


pooling to work... arrrgghh...
I got the configuration as stated in email below.. except my path


is


empty ("").

I created a simple java test and inside the main(), I just call


the


DatabaseOperation class
and it should initialize all the connections.  The error I got as
follows:

javax.naming.NoInitialContextException: Need to specify class name


in


environment
or system property, or as an applet parameter, or in an


application


resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown


Source)


at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown


Source)


at javax.naming.InitialContext.lookup(Unknown Source)
at com.maxis.app.DatabaseOperation.initialConnection

I've specified the <name>driverClassName</name> in server.xml.


Isn't


this value
loaded in my environment/system property? What is application


resource


file?

Any ideas/suggestions?
BTW, if I use Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("....") coding, that works fine..
I can connect to database.

Thanks,
--Kawthar



[EMAIL PROTECTED] 19/03/2004 10:12:17 PM >>>


If I could see the error it would help but I don't think your
datasource is
getting loaded correctly into JNDI.  The full name of the jar in
common/lib
works fine.
Here is the context.xml I used based on the HOW_TO and it works
great.  If this file doesn't work, it is most likely a location or
alternate
error.

<Context path="/DBTest" docBase="DBTest"
       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>
   <parameter>
     <name>maxActive</name>
     <value>100</value>
   </parameter>
   <parameter>
     <name>maxIdle</name>
     <value>30</value>
   </parameter>
   <parameter>
     <name>maxWait</name>
     <value>10000</value>
   </parameter>
   <parameter>
    <name>username</name>
    <value>javauser</value>
   </parameter>
   <parameter>
    <name>password</name>
    <value>javadude</value>
   </parameter>
   <parameter>
      <name>driverClassName</name>
      <value>com.mysql.jdbc.Driver</value>
   <parameter>
     <name>url</name>

<value>jdbc:mysql://localhost/javatest?autoReconnect=true</value>
   </parameter>
 </ResourceParams>
</Context>

-----Original Message-----
From: Kawthar Bt M Sulaiman [mailto:[EMAIL PROTECTED] Sent: Thursday, March 18, 2004 6:52 PM
To: [EMAIL PROTECTED] Subject: Re: JDBC/mySQL problem.


Yes, I have the latest connector inside my /common/lib.
mysql-connector-java-3.0.11-stable-bin.jar

I even tried naming this without the word "stable" in it, and


still


not
working.

In my log file, I can see the following:
Creating JNDI naming context

Resource parameters for jdbc/mySQLDatabase =
ResourceParams[name=jdbc/mySQLDatabase,



parameters={url=jdbc:mysql://localhost:3306/ecpa?autoReconnect=true,


serverName=localhost, maxActive=100,
drvierClassName=com.mysql.jdbc.Driver, removeAbandoned=true,
username=root,


factory=org.apache.commons.dbcp.BasicDataSourceFactory,


password=xxx}]

ResourceRef[className=javax.sql.DataSource,


factoryClassLocation=null,


factoryClassName=org.apache.naming.factory.ResourceFactory,


.....<same


info as above>]

Do you see anything strage?  The factoryClassLocation is NULL.. is
this
a problem?

Thanks,
--Kawthar



[EMAIL PROTECTED] 18/03/2004 09:36:37 PM >>>


hi my aplication use mysql and the conection config looks like


that:


(piece)
<DRIVER>com.mysql.jdbc.Driver</DRIVER>
<URL>jdbc:mysql://localhost:3306/database</URL>
<LOGIN>root</LOGIN>
<PASSWORD></PASSWORD>you dont need password wen your in local
context
+did you downloader the latest connecter
mysql-connector-java-3.0.10-stable-bin from mysql and copied it


under


your
comon /lib +/lib of your aplication ?
here everyting works fine and im on tomcat 4.0

----- Original Message ----- From: "Parsons Technical Services"


<[EMAIL PROTECTED]>


To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Thursday, March 18, 2004 12:29 AM
Subject: Re: JDBC/mySQL problem.




Kawthar,

As for Steve's concerns:
It is the same one. The short story: Mark Mathews wrote it MySQL


liked it


and adopted it and him. So it went from org.gjt.mm to com.mysql.


Both
names


will work fine but to be up to date use the com.mysql.

As for server.xml having only one is fine, and on TC4 this is


common.
If
you


move to TC5 then you can have multiple files with each part


applying


to
only


the app that it is included with. For now don't worry about it.

If your application is running OK as ROOT other than the DBCP


problems
then


you are fine. It is that most people set up a new context and


don't


mess


with the ROOT at first. But again if the rest of the app runs


you're


fine.


Now for fifty questions:
You are rebooting after changes? It has bitten me several times.

Have you done a manual connection?
Class.forName("com.mysql.jdbc.Driver");
connection =
DriverManager.getConnection(
"jdbc:mysql://localhost:3306/ecpa",
"youruser",
"yourpassword");

If the manual connection fails then:
Can you access the database directly and log on using the


username


and


password that is in the context?

Can you open a prompt and ping localhost? I have seen it fail.
If so use the IP of your machine if you can ping it otherwise


you


have
other


issues.

Are you running a firewall on the machine?

What OS are you on?

What are the rights for the user in the database, can the user


gain


access


from localhost?

Doug


----- Original Message ----- From: "Kawthar Bt M Sulaiman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 17, 2004 11:46 PM
Subject: Re: JDBC/mySQL problem.





Followed your suggestion, but still not working.

Thnx,
--Kawthar



[EMAIL PROTECTED] 18/03/2004 12:18:00 PM >>>


Kawthar,

Change:

 <Resource auth="Container" description="JDBC Connection to
MySQL v4.0.18" name="mySQLDatabase" scope="Shareable"
type="javax.sql.DataSource"/>

    <Resource name="jdbc/mySQLDatabase" auth="Container"
type="javax.sql.DataSource"/>

To:

 <Resource auth="Container" description="JDBC Connection to
MySQL v4.0.18" name="jdbc/mySQLDatabase" scope="Shareable"
type="javax.sql.DataSource"/>

Should work either way, mine did, just cleaner and proper.
Note name is changed in second entry, added jdbc/  .


Doug


----- Original Message ----- From: "Parsons Technical Services"


<[EMAIL PROTECTED]>


To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Wednesday, March 17, 2004 11:02 PM
Subject: Re: JDBC/mySQL problem.




Kawthar,

Try this context in place of yours.

<Context path="/db" docBase ="ROOT" debug="9"


reloadable="true">


<Resource auth="Container" description="JDBC Connection to
MySQL v4.0.18" name="mySQLDatabase" scope="Shareable"
type="javax.sql.DataSource"/>

   <Resource name="jdbc/mySQLDatabase" auth="Container"
type="javax.sql.DataSource"/>

         <ResourceParams name="jdbc/mySQLDatabase">
          <parameter>
          <name>factory</name>




<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>


          </parameter>
          <parameter>
            <name>username</name>
           <value>xxxx</value>
           </parameter>
             <parameter>
                <name>password</name>
              <value>xxxx</value>
            </parameter>
         <parameter>
         <name>maxActive</name>
         <value>100</value>
         </parameter>
   <parameter>
     <name>maxIdle</name>
     <value>5</value>
   </parameter>
   <parameter>
     <name>maxWait</name>
     <value>10000</value>
   </parameter>

       <parameter>
         <name>driverClassName</name>
         <value>org.gjt.mm.mysql.Driver</value>
         </parameter>
         <parameter>
          <name>url</name>



<value>jdbc:mysql://localhost:3306/ecpa?autoReconnect=true</value>


         </parameter>
      </ResourceParams>

<Logger


className="org.apache.catalina.logger.FileLogger"


                    prefix="DBlog." suffix=".txt"
             timestamp="true"/>
    </Context>

Don't forget to close the statement and the result set.
I do mine in a finally block along with the conn.close() and


each
one


is


wrapped in a try / catch.

Make sure to restart Tomcat after you make changes to the


server.xml.


Doug






---------------------------------------------------------------------


To unsubscribe, e-mail:


[EMAIL PROTECTED]

For additional commands, e-mail:


[EMAIL PROTECTED]






---------------------------------------------------------------------


To unsubscribe, e-mail:


[EMAIL PROTECTED]



For additional commands, e-mail:


[EMAIL PROTECTED]






---------------------------------------------------------------------


To unsubscribe, e-mail:


[EMAIL PROTECTED]



For additional commands, e-mail:


[EMAIL PROTECTED]





---------------------------------------------------------------------


To unsubscribe, e-mail:


[EMAIL PROTECTED]

For additional commands, e-mail:


[EMAIL PROTECTED]







---------------------------------------------------------------------


To unsubscribe, e-mail: [EMAIL PROTECTED]





For additional commands, e-mail:


[EMAIL PROTECTED]





---------------------------------------------------------------------


To unsubscribe, e-mail: [EMAIL PROTECTED]





For additional commands, e-mail:


[EMAIL PROTECTED]

Confidential information may be contained in this e-mail and any


files
transmitted with it ('Message'). If you are not the addressee


indicated


in
this Message (or responsible for delivery of this Message to such
person),
you are hereby notified that any dissemination, distribution,


printing


or
copying of this Message or any part thereof is strictly prohibited.


In


such
a case, you should delete this Message immediately and advise the
sender by
return e-mail. Opinions, conclusions and other information in this
Message
that do not relate to the official business of Maxis shall be
understood as
neither given nor endorsed by Maxis.




---------------------------------------------------------------------


To unsubscribe, e-mail: [EMAIL PROTECTED]





For additional commands, e-mail:


[EMAIL PROTECTED]







---------------------------------------------------------------------


To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





Confidential information may be contained in this e-mail and any


files
transmitted with it ('Message'). If you are not the addressee indicated
in
this Message (or responsible for delivery of this Message to such
person),
you are hereby notified that any dissemination, distribution, printing
or
copying of this Message or any part thereof is strictly prohibited. In
such
a case, you should delete this Message immediately and advise the
sender by
return e-mail. Opinions, conclusions and other information in this
Message
that do not relate to the official business of Maxis shall be
understood as
neither given nor endorsed by Maxis.




---------------------------------------------------------------------


To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]










---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Confidential information may be contained in this e-mail and any files transmitted with it ('Message'). If you are not the addressee indicated in this Message (or responsible for delivery of this Message to such person), you are hereby notified that any dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. In such a case, you should delete this Message immediately and advise the sender by return e-mail. Opinions, conclusions and other information in this Message that do not relate to the official business of Maxis shall be understood as neither given nor endorsed by Maxis.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to