Solved

jdbc odbc problem

Posted on 2002-06-11
7
418 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
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
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.

 
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

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

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…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

911 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

22 Experts available now in Live!

Get 1:1 Help Now