Solved

jdbc odbc problem

Posted on 2002-06-11
7
408 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
noX challenge 17 77
json example 39 116
word0 challenge 3 59
Where to store the queries for modification of table 4 29
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

14 Experts available now in Live!

Get 1:1 Help Now