Solved

jdbc odbc problem

Posted on 2002-06-11
7
426 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
thymeleaf natural templating vs JSP 2 97
xampp tool 12 49
Java: How do I open the default windows program for a given file type 3 28
Desingning Refactoring existing code 2 24
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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 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