• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC drivers/getting JDBC started

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check for your classpath
The classpath is not set to the drive where your source file resides
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
And Green
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much to you both, all sorted now!
 
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic