Solved

JDBC-ODBC error

Posted on 2001-07-03
5
338 Views
Last Modified: 2010-07-27
I am learning Java(JDBC)
This is the code:

import java.sql.*;
     
public class CreateCoffees {

     public static void main(String args[]) {
           
          String url = "jdbc:odbc:Northwind";
          Connection con;
          String createString;
          createString = "create table COFFEES " +
                                   "(COF_NAME varchar(32), " +
                                   "SUP_ID int, " +
                                   "PRICE float, " +
                                   "SALES int, " +
                                   "TOTAL int)";
          Statement stmt;
     
          try {
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

          } catch(java.lang.ClassNotFoundException e) {
               System.err.print("ClassNotFoundException: ");
               System.err.println(e.getMessage());
          }

          try {
               con = DriverManager.getConnection(url,
                                              "sa", "");
     
               stmt = con.createStatement();                                  
                      stmt.executeUpdate(createString);
     
               stmt.close();
               con.close();
     
          } catch(SQLException ex) {
               System.err.println("SQLException: " + ex.getMessage());
          }
     }
}

This is the error:

Exception in thread "main" java.lang.NoClassDefFoundError: c:\javs\jdbc3\codeExa
mples\firstEdition\CreateCoffees

what causes this error?

I have setup the DSN Northwind already.
what is wrong with this line:

Class.forname(sun..........)?

How do I find out if this Drive class exited? I did install JDK1.3.1 on my winnt4 machine

Thanks
0
Comment
Question by:chrislee8
  • 3
5 Comments
 
LVL 2

Expert Comment

by:iDeb
ID: 6249208
This error is as a result of your classpath not being ser to the location of the class CreateCoffees.....so include the location of CreateCoffees.class in your classpath
0
 
LVL 2

Expert Comment

by:iDeb
ID: 6249222
Besides you mean Class.forName("sun.....") right?.....as you might know java methods are casesensitive and the argument is a String
0
 
LVL 2

Expert Comment

by:iDeb
ID: 6249237
oops please delete my comments, i didn't read the code entirely.....
0
 
LVL 1

Accepted Solution

by:
ny971181 earned 50 total points
ID: 6250005
do this:

c:> cd to your porject directory
c:project dir>c:\jdk1.3.1\bin\javac -classpath . project.java

now you will see the class file the javac just created.

c:project dir>c:\jdk1.3.1\bin\java -classpath . project(this is the class file)

0
 

Author Comment

by:chrislee8
ID: 6250013
it is that easy. thank you
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Running Jira on Raspberry PI 2? 3 139
unix in java example 9 43
backtracking recursion  code 19 41
ArrayIndexOutOfBoundException 9 39
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

746 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

13 Experts available now in Live!

Get 1:1 Help Now