The MySQL database was never the problem. The problem was the resource wasn't being loaded into the JNDI. Problem was the context segement of my config.
-----Original Message----- From: Tom K [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 17, 2004 6:09 PM To: 'Tomcat Users List' Subject: RE: JDBC problems with MySQL I am new to this list as of today, so I don't know if anyone has already answered your question. Tomcat will not connect to mysql unless you have a password and of course rights to the database. Here is an example. Use these mySQL commands mysql -u root (This command gives your root privledges). CONNECT YourDatabase GRANT ALL PRIVILEGES ON *.* TO [EMAIL PROTECTED] IDENTIFIED BY "Yourpassword" WITH GRANT OPTION; You must have a password for Tomcat to work with mySQL Note: the above user should be removed once testing is complete! /********* Next, put something like this in your server.xml file: *****/ - <Context path="/classified" docBase="classified" debug="5" reloadable="true" crossContext="true"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_Classifieds_log." suffix=".txt" timestamp="true" /> <Resource name="jdbc/Classifieds" auth="Container" type="javax.sql.DataSource" /> - <ResourceParams name="jdbc/Classifieds"> - <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>100</value> </parameter> - <!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. --> - <parameter> <name>maxIdle</name> <value>30</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> - <!-- To configure a DBCP DataSource so that abandoned dB connections are removed and recycled --> - <parameter> <name>removeAbandoned</name> <value>true</value> </parameter> - <!-- MySQL dB username and password for dB connections --> - <parameter> <name>username</name> <value>tkoc</value> </parameter> - <parameter> <name>password</name> <value>trustno1</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:3306/Classifieds?autoReconnect=true</value > </parameter> </ResourceParams> </Context> /* NOTE THAT Classifieds would be my JNDI datasource see the servlet code below*/ IF CONNECTING VIA A SERVLET PUT THIS CODE BEFORE doPost/doGet public void init(ServletConfig config) throws ServletException{ super.init(config); try{ System.out.println("init() DeleteDBServlet: Start Loading Database Driver"); Context env = (Context) new InitialContext().lookup("java:comp/env"); pool = (DataSource) env.lookup("jdbc/Classifieds"); if (pool == null) throw new ServletException("`jdbc/Classifieds' is an unknown DataSource"); }catch (NamingException e) { throw new ServletException(e); } } I hope this helps, Tom Kochanowicz -----Original Message----- From: Kumar Abhay-CAK203C [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 12:01 PM To: 'Tomcat Users List' Subject: RE: JDBC problems with MySQL Importance: High Dear Steve, I posted this problem around 3 months back and I am daily reading the forum, hoping that one day somebody will give a solution. I will deeply appreciate you if u share the solution with me if u r able to find. Good Luck Best Regards Abhay Kumar -----Original Message----- From: Steve Gums [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 11:57 AM To: [EMAIL PROTECTED] Subject: JDBC problems with MySQL Users I know there has been a bazillion messages about this. I searched the archives and couldn't find anything to solve my extremely annoying issue. It has to be something really simple but I just can't find it. My System: Solaris 9 Tomcat 5.0.19 MySQL 4.0.18 Connector J 3.0.11 I have the connector J jar in the /usr/local/tomcat/common/lib dir. I have basically copied the HOW-TO located at. http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples -how to.html and my result is this. Results Foo Not Connected Bar -1 I have tried everything I can think of. I verified the database and the user/password combo. Works good. I even created a simple Java app that connects and performs queries, which worked. That would indicate everything is cool with the Connector J. I have verified that the jdbc/TestDB is in the context and it is. As best I can tell ds (DataSource) is coming back not null, but the call to getConnection is failing. I created a little more verbose web app and get the following message. org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver This has to be something simple, because this works fine on my old machine. I know I am forgetting some small step that I did the first time and failed to do again. Trust me I have checked the configs about a million times, and can't find any differences. Any help would be appreciated. Sorry to be so vague here, but this is really simple. I don't know what else to include for info. Steve Gums [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.557 / Virus Database: 349 - Release Date: 12/30/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.557 / Virus Database: 349 - Release Date: 12/30/2003 --------------------------------------------------------------------- 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]
