Solved

JDBC-ODBC error

Posted on 2001-07-03
5
339 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript/Java - Changing an image background color 4 56
Java JRE greater than 1.6 5 51
servlet example issue 6 32
Error in @AspectJ Based AOP with Spring 2 4
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

867 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

23 Experts available now in Live!

Get 1:1 Help Now