Solved

JDBC-ODBC error

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JList custom Cell Renderer refresh 15 57
Apps blocked by Java 9 81
type mismatch (Object[] to double[] 4 24
How to execute a Python program and gather return output in Java 2 31
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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

803 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