This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Tomcat/MYSQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat/MYSQL" Watch "Tomcat/MYSQL" New topic
Author

Tomcat/MYSQL

meerap pillaii
Greenhorn

Joined: Dec 03, 2007
Posts: 7
hi friends

When i try to connect to MYSQL in tomcat project, i can't connect that.The same program run fine without tomcat project.

Please help me

Code is
Connection conn = null;
String userName = "root";
String password = "rootpwd";
String url = "jdbc:mysql://localhost/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);

This code is working fine without tomcat
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41060
    
  43
i can't connect that.

What does this mean? Have you checked the Tomcat logs files if there are any error messages? If so, which ones?

Have you put the DB driver jar file into WEB-INF/lib directory of the web application you're running this code in? Remember that Tomcat doesn't use the standard system classpath.


Ping & DNS - my free Android networking tools app
meerap pillaii
Greenhorn

Joined: Dec 03, 2007
Posts: 7
First of all thank you for your replay

The problem is at the line
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
where connection can't establish...I copied the connector
mysql-connector-java-5.0.8 into lib folder..Yet the prob persist
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41060
    
  43
You still haven't told us WHAT the problem is - post the complete error message and stack trace.

Have you restarted the web app after copying the jar file?

You should remove the ".newInstance()" method call by the way. It's not needed.
[ December 19, 2007: Message edited by: Ulf Dittmer ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Tomcat/MYSQL
 
Similar Threads
No suitable driver found
com.mysql.jdbc.exceptions.jdbc4.communicationsexception communications link failure
simple Sql connectivity problem
MySQL Connector/J
i couldn't run jdbc progam in netbeans