tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <ke...@witten-enterprises.com>
Subject Re: Help getting MySQL connected to Tomcat
Date Sun, 24 Feb 2008 17:13:38 GMT
Thanks for the help. I still don't have this working completely, but tomcat 
is now working.

I tested mysql and it is using tcp/ip. "mysql -h 127.0.0.1 -u javauser -p" 
works fine.
Also the MSQLAdmin program shows it is connecting to the correct port 3306

I see your point about purring the resource in conf/context.xml, I will move 
it.
But from reading online forums, I have come across two suggestions:
1) put a context.xml in the WEB-INF dir of you webapp
2) put the <Context> in <tomcat>\conf\localhost\<webappname>.xml

I would guess that 1) is correct, so that is what I did. Attached is my 
current context.xml from this webapp

So now Tomcat starts with no errors, but when I try to run my jsp which uses 
a DAO in java I get errors:

last one SQLException is also in the localhost log and seems to be the cause
org.apache.jasper.JasperException: Cannot create JDBC driver of class '' for 
connect URL 'null'
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause javax.servlet.ServletException: Cannot create JDBC driver of 
class '' for connect URL 'null'
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
	org.apache.jsp.rates_jsp._jspService(rates_jsp.java:101)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create 
JDBC driver of class '' for connect URL 'null'
	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1150)
	org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
	converters.ConversionDAO.<init>(ConversionDAO.java:23)
	org.apache.jsp.rates_jsp._jspService(rates_jsp.java:46)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause java.sql.SQLException: No suitable driver
	java.sql.DriverManager.getDriver(DriverManager.java:243)
	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
	org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
	converters.ConversionDAO.<init>(ConversionDAO.java:23)
	org.apache.jsp.rates_jsp._jspService(rates_jsp.java:46)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache 
Tomcat/5.5.26 logs.
Herer is my java code for the DAO, line 23 gets the connection from the 
DataSource.

public class ConversionDAO

{

      private Connection con;

      private PreparedStatement select;

      private PreparedStatement update;

      private String src;

      private String dst;

      private double rate;



      public ConversionDAO() throws SQLException, NamingException

      {

            Context init = new InitialContext();

            Context ctx = (Context) init.lookup("java:comp/env");

            DataSource ds = (DataSource) ctx.lookup("jdbc/CurrencyDB");

            con = ds.getConnection(); // THIS IS LINE 23

            select = con.prepareStatement("SELECT rate FROM exchange WHERE 
src = ? and dst = ?");

            update = con.prepareStatement("UPDATE Exchange SET rate = ? 
WHERE src = ? NAD dst = ?");

      }

        ...

}


So why can't it find a driver.
I put the mysql-connector-java-5.1.5-bin.jar in <tomcat>\common\lib

Thanks again for any help.

Kevin

----- Original Message ----- 
From: "Christopher Schultz" <chris@christopherschultz.net>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Sunday, February 24, 2008 8:06 AM
Subject: Re: Help getting MySQL connected to Tomcat


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Kevin,
>
> kevin@witten-enterprises.com wrote:
> | I've tried following the directions from the tomcat dist and from the
> | mysql dist but I always get can't connect exceptions when I start 
> tomcat.
>
> "Connection refused" usually means that everything is configured
> properly on the Java/Tomcat side (except maybe the port number, though
> yours is correct) and MySQL isn't picking up the phone for some reason.
> David's reply regarding the networking options for MySQL is a good place
> to start. Check your my.ini (or mysql.ini, or whatever it happens to be)
> and make sure that the "skip-networking" option is not currently
> enabled. I'm not sure how MySQL fares on win32 without networking, but
> presumably the mysql client can connect via a named pipe rather than
> using TCP/IP.
>
> To see if MySQL is using networking (which is required by MySQL
> Connector/J), try this:
>
> C:\whatever> mysql -h 127.0.0.1 -u javauser -p
>
> This will force the command-line tool to use TCP/IP instead of other
> means to connect to the server (note that "localhost" won't work, since
> the tool is documented to use the named pipe if the string "localhost"
> is used. Using the IP address will avoid this behavior). If the
> connection fails, then you have disabled networking in MySQL and need to
> enable it.
>
> | I can connect to the database from the console using "C:> mysql -u
> | javauser -p" and I can then connect to the javatest DB and select * from
> | the table works fine.
> |
> | Then I added the following to in the <tomcat>/conf/context.xml file
>
> This is not your problem, but you really shouldn't put your <Resource>
> element in <tomcat>/conf/context.xml; instead, you should create an
> application-specific context.xml and put it in there. What you are doing
> will expose that DataSource to all applications deployed in your 
> container.
>
> | <Context path="/db-servlet" docBase="db-servlet" debug="5"
> reloadable="true" crossContext="true">
>
> You should not define docBase in context.xml, ever. Also, I'm not
> entirely sure, but I don't think you can set a path in the default
> context.xml... it will probably be ignored. Again, these issues aren't
> your (current) problem, but you should fix them, anyway.
>
> |
> |    <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"/>
> |
> | </Context>
> |
> |
> |
> | And I stop tomcat, and when I restart tomcat I get the following in
> the catalina log:
> |
> |
> |
> | ...
> |
> | INFO: Stopping Coyote HTTP/1.1 on http-8080
> |
> | Feb 23, 2008 8:31:19 AM org.apache.catalina.core.AprLifecycleListener
> lifecycleEvent
> |
> | INFO: Failed shutdown of Apache Portable Runtime
> |
> | Feb 23, 2008 8:37:40 AM org.apache.catalina.startup.Catalina stopServer
> |
> | SEVERE: Catalina.stop:
> |
> | java.net.ConnectException: Connection refused: connect
> |
> |       at java.net.PlainSocketImpl.socketConnect(Native Method)
> |
> |       at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> |
> |       at
> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> |
> |       at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> |
> |       at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
> |
> |       at java.net.Socket.connect(Socket.java:520)
> |
> |       at java.net.Socket.connect(Socket.java:470)
> |
> |       at java.net.Socket.<init>(Socket.java:367)
> |
> |       at java.net.Socket.<init>(Socket.java:180)
> |
> |       at
> org.apache.catalina.startup.Catalina.stopServer(Catalina.java:395)
> |
> |       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> |
> |       at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> |
> |       at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> |
> |       at java.lang.reflect.Method.invoke(Method.java:585)
> |
> |       at
> org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:344)
> |
> |       at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:435)
> |
> |
> |
> |
> |
> | So why the connection refused?
> |
> |
> |
> | Any help is appreciated.
> |
> |
> |
> | Thanks,
> |
> | Kevin
> |
> |
> |
> |
> |
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkfBlhoACgkQ9CaO5/Lv0PD/GQCcCv1o2CwggigU3W5gu2VYRXGn
> HfYAoJS5O+gITnVRYbNML7J+jP7CG+pA
> =Snl6
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

Mime
View raw message