• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Tomcat/MYSQL

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
meerap pillaii
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic