Solved

problems with database connections

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object methods vs static methods 2 97
jersey maven project error 7 141
Fisheye tool 2 111
maven j2ee examles 2 55
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The question appears often enough, how do I transfer my data from my old server to the new server while preserving file shares, share permissions, and NTFS permisions.  Here are my tips for handling such a transfer.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

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