?
Solved

problems with database connections

Posted on 2003-11-17
6
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 80 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Introducing Priority Question, our latest feature.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

777 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