Solved

jdbc odbc problem

Posted on 2002-06-11
7
436 Views
Last Modified: 2010-05-18
hi,
i got the following error:
C:\>java JDBCTest3
java.lang.ClassNotFoundException: sun.jdbc.odbc.JbdcOdbcDriver


Here is my code:
import java.sql.*;
import java.io.*;
import java.util.*;

public class JDBCTest3
{

     public static void main(String[] args)
     {
     
          //String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
          String driver = "sun.jdbc.odbc.JbdcOdbcDriver";
          //String DBurl = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=stanley;User=stanley;Password=xxxxxx";
          String DBurl = "jdbc:odbc:ciuser";
         
     
          try
          {
               String query ="create table testing (name char(20));";
               String name = "";
               
               Class.forName(driver);
               java.sql.Connection con = DriverManager.getConnection(DBurl, "ciuser", "ciuser");
/*
               String createProcedure = "drop procedure TEST_PROC; create procedure TEST_PROC " +
                "as " +
                "select * " +
                "from stanley";



               CallableStatement cs = con.prepareCall("{call TEST_PROC}");
               ResultSet rs = cs.executeQuery();


*/

               Statement stmt = con.createStatement();
               stmt.execute(query);


               
               //Statement ps = con.createStatement();
               //java.sql.ResultSet rs = ps.executeQuery(query);
               //while(rs.next())
               //{
                   
               //     name = rs.getString(1);
               //     System.out.println("name is "+name);
                   
               //}
               //System.out.println("select is ok");
               //rs.close();
               //cs.close();

               con.close();
          }
          catch(Exception e)
          {
               System.out.println(e);
               System.exit(1);    
          }
 
     }    
}
     
0
Comment
Question by:stanleyhuen
[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
7 Comments
 
LVL 6

Expert Comment

by:kotan
ID: 7071852
make sure the package sun.jdbc.odbc.JbdcOdbcDriver is in ur classpath.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7071990
Reinstall your jdk.
0
 

Expert Comment

by:thangnt
ID: 7072125
Hi,

I think you miss something in your code, please see it in below :)

Thanks,

import java.sql.*;
import java.io.*;
import java.util.*;

public class JDBCTest3
{

    public static void main(String[] args)
    {
   
         //String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
         String driver = "sun.jdbc.odbc.JbdcOdbcDriver";
         //String DBurl = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=stanley;User=stanley;Password=xxxxxx";
         String DBurl = "jdbc:odbc:ciuser";
         
     
         try
         {
              String query ="create table testing (name char(20));";
              String name = "";
             
              //This is your missing
              Class.forName(driver);
              //////////////////////////////////////
              //And this is my idea
              //Class.forName(driver).newInstance();
              //////////////////////////////////////

              java.sql.Connection con = DriverManager.getConnection(DBurl, "ciuser", "ciuser");
/*
              String createProcedure = "drop procedure TEST_PROC; create procedure TEST_PROC " +
               "as " +
               "select * " +
               "from stanley";



              CallableStatement cs = con.prepareCall("{call TEST_PROC}");
              ResultSet rs = cs.executeQuery();


*/

              Statement stmt = con.createStatement();
              stmt.execute(query);


             
              //Statement ps = con.createStatement();
              //java.sql.ResultSet rs = ps.executeQuery(query);
              //while(rs.next())
              //{
                   
              //     name = rs.getString(1);
              //     System.out.println("name is "+name);
                   
              //}
              //System.out.println("select is ok");
              //rs.close();
              //cs.close();

              con.close();
         }
         catch(Exception e)
         {
              System.out.println(e);
              System.exit(1);    
         }

    }    
}
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 9

Expert Comment

by:Venci75
ID: 7072129
... or add
<JAVA_PATH>\jre\lib\rt.jar to your class path.

0
 

Author Comment

by:stanleyhuen
ID: 7072173
Thanks.

Sorry, I found the mistake now.
It is typing mistake:
sun.jdbc.odbc.JbdcOdbcDriver

should be:


sun.jdbc.odbc.JdbcOdbcDriver
0
 

Accepted Solution

by:
YSaadat earned 200 total points
ID: 7072315
Hi,

Here is a silly mistake.
check the spelling
String driver = "sun.jdbc.odbc.JbdcOdbcDriver";
         
It should be
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

Regards
Saadat
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7072318
good answer :))
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to determine if a string is a valid SHA value 7 44
Which non-HTML GUI front end to use with Java? 3 52
wild fly 8 startup error 2 43
Java array 10 63
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.

726 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