Solved

JDBC-ODBC error

Posted on 2001-07-03
5
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

635 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