Solved

problems with database connections

Posted on 2003-11-17
6
313 Views
Last Modified: 2010-04-01
hai !!!

i'm trying to develop a web application using jsp and mysql as database . after reading the websites i came to a understanding that i need to install a jdbc driver .. i did that after downloading that and placed that on the  path C:\j2sdk1.4.2\jre\lib\ext\mysql-connector-java-3.0.9-stable-bin.jar .. i even changed the class path in the environment variables settings to
CLASSPATH=.;C:\j2sdk1.4.2\jre\lib\ext\mysql-connector-java-3.0.9-stable-bin.jar.

i tried to connect to the database using the following code but the connection to the database cannot be established ..please help me ..tell me what am i doing wrong and please suggest the correct way to do .

import java.sql.*;

public class JdbcExample1 {

  public static void main(String args[]) {
    Connection con = null;

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql:///test", "root", "root");

      if(!con.isClosed())
        System.out.println("Successfully connected to MySQL server...");

    } catch(Exception e) {
      System.err.println("Exception: " + e.getMessage());
    } finally {
      try {
        if(con != null)
          con.close();
      } catch(SQLException e) {}
    }
  }
}




i get the following exception :Exception: com.mysql.jdbc.Driver

please help me i'm very new to java programming

raghu
0
Comment
Question by:Raghunandan44
  • 3
6 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9770027
If you're using that JAR file, then you want the following Class.forName():

Class.forName("org.gjt.mm.mysql.Driver");

You shouldn't need the newInstance() on the end.

The URL in the line:

>> con = DriverManager.getConnection("jdbc:mysql:///test", "root", "root");

should include your server before the database name, eg:

con = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "root");


What is the full exception that is being displayed?
0
 

Author Comment

by:Raghunandan44
ID: 9771616
hai !!
thank u for u'r reply ..i did  the changes that you suggested in the reply and tried to compile and run the file. i still have that exception. " Exception: org.gjt.mm.mysql.Driver ".
please help me ..
thank you

raghu
0
 
LVL 15

Accepted Solution

by:
jimmack earned 20 total points
ID: 9771701
mysql-connector-java-3.0.9-stable-bin.jar should appear in your path for the web service, eg:

From kennethxu's comment in http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_20799034.html

common/lib - visible by both tomcat server and all apps. for example, jdbc drivers.
server/lib - will only be accessed by tomcat server itself, not visible by apps.
shared/lib - visible by all apps, not visible to tomcat server. for example, your own util lib for all apps.
WEB-INF/lib - only visible by the app that contains the WEB-INF dir.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9772883
what app server r u using?
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9773373
Good point ;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exception creating bean of class 5 219
getting Http 404 error in jsp forms 8 85
constructor overloading 2 93
How to Post an If Statement in JSP 3 65
This article was originally published on Monitis Blog, you can check it  here .   Some years back, I worked as the CTO.  During my tenure, I had a head of IT support reporting to me.  He did his job quite well and had a commendable sense of duty…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question