Solved

problems with database connections

Posted on 2003-11-17
6
309 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 163
String format issue 13 90
Spring MVC - sending raw charset to backend 3 188
doubleChar java challenge 7 102
When converting a physical machine to a virtual machine using VMware vCenter Converter Standalone or vCenter Converter Enterprise, if an adapter type is not selected during the initial customization the resulting virtual machine may contain an IDE d…
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

20 Experts available now in Live!

Get 1:1 Help Now