Solved

problems with database connections

Posted on 2003-11-17
6
308 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
what app server r u using?
0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
Good point ;-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now