File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JDBC drivers/getting JDBC started Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC drivers/getting JDBC started" Watch "JDBC drivers/getting JDBC started" New topic
Author

JDBC drivers/getting JDBC started

And Green
Greenhorn

Joined: Sep 28, 2007
Posts: 26
I am trying to use JDBC with MySQL. I�m a total novice as far as JDBC is concerned so apologies if my errors are glaringly obvious, but I�m not finding the instructions on Java�s sun site and the MYSQL site, not very helpful.

I have successfully installed and tested MYSQL on my PC and am running JRE and JDK 6.

I have downloaded the JDBC driver from MYSQL and added a classpath to the environment variables �C:\mysql-connector-java-5.1.5\mysql-connector-java-5.1.5\mysql-connector-java-5.1.5-bin.jar� which points to the necessary file as per the My SQL instructions.

I have then been instructed to compile a java program that loads the drivers.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class LoadDriver
{
public static void main (String [] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Driver Loaded");
}
catch (Exception ex)
{
System.out.println("Failure");
}
}
}

I have compiled this file in a folder Desktop\Myjava. When I run it from the command line it just says �Exception in thread �main� java.lang.NoClassDefFoundError: LoadDriver.

Any instructions on how to get my JDBC drivers working, much appreciated.
Suvidha Agarwal
Greenhorn

Joined: Oct 11, 2007
Posts: 4
Check for your classpath
The classpath is not set to the drive where your source file resides


Where there is a will, there is a way!!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Can you try executing this command before running the code:

and than run your java file?
The dot will add your current directory (where your own compiled class is stored) to the classpath.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
And Green
Greenhorn

Joined: Sep 28, 2007
Posts: 26
Thanks very much to you both, all sorted now!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC drivers/getting JDBC started
 
Similar Threads
NoClassDefFoundError
another JDBC driver question
MySQL Beginner Has Problem With Loading JDBC Driver
Issue First JDBC Pgm
Help needed with JDBC driver