Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JDBC-ODBC error

Posted on 2001-07-03
5
Medium Priority
?
346 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 200 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

704 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