The Artima Developer Community
Sponsored Link

Java Answers Forum
can't load java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

2 replies on 1 page. Most recent reply: Sep 25, 2006 12:44 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Horacio Tovar

Posts: 1
Nickname: hetch
Registered: Sep, 2006

can't load java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver Posted: Sep 22, 2006 4:58 PM
Reply to this message Reply
Advertisement
PLEASE HELLP!!!!
Hi guys, I am almost crazy with this problem. THANK YOU!

I am doing a little and simple program to connect from Microsoft Visual j# .NET java program to an Access database. I am getting this error:

java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
at com.ms.vjsharp.lang.VJSClassLoader.loadClass(String name, Boolean resolve)
at com.ms.vjsharp.lang.VJSClassLoader.__getClassFromClassLoader(VJSClassLoader ld, String className)
at com.ms.vjsharp.lang.VJSClassLoader.loadClass(String name)
at java.lang.Class.forName(String className, Assembly callerA)
at java.lang.Class.forName(String className)
at ConnectProject.Connect.getConnection() in F:\Vigo\ConnectProject\ConnectProject\Connect.jsl:line 30
Error Trace in getConnection() : sun.jdbc.odbc.JdbcOdbcDriver

I have tried different forums and read a lot on internet, I set my CLASSPATH in this way:

CLASSPATH=C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;c:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;c:\j2sdk1.4.2_12\bin\rt.jar

I checked the files msbase.jar, msutil.jar and mssqlserver.jar exist in the directory. Also, the rt.jar is in c:\j2sdk1.4.2_12\bin\rt.jar.

Please somebody help me, I am being stuck here for 2 weeks.

Here is the code I am using:

package ConnectProject;

import java.*;
public class Connect
{
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "localhost";
private final String portNumber = "1433";
private final String databaseName= "pubs";
private final String userName = "user";
private final String password = "password";
// Informs the driver to use server a side-cursor,
// which permits more than one active statement
// on a connection.
private final String selectMethod = "cursor";

// Constructor
public Connect(){}

private String getConnectionUrl()
{
return
url+serverName+":"+portNumber+";databaseName="+data baseName+";selectMethod="+selectMethod+";";
}

private java.sql.Connection getConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = java.sql.DriverManager.getConnection
(getConnectionUrl(),userName,password);
if (con!=null) System.out.println("Connection
Successful!");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " +
e.getMessage());
}
return con;
}

/*
Display the driver properties, database details
*/

public void displayDbProperties()
{
java.sql.DatabaseMetaData dm = null;
java.sql.ResultSet rs = null;
try
{
con= this.getConnection();
if(con!=null)
{
dm = con.getMetaData();
System.out.println("Driver Information");
System.out.println("\tDriver Name: "+
dm.getDriverName());
System.out.println("\tDriver Version: "+
dm.getDriverVersion ());
System.out.println("\nDatabase Information ");
System.out.println("\tDatabase Name: "+
dm.getDatabaseProductName());
System.out.println("\tDatabase Version: "+
dm.getDatabaseProductVersion());
System.out.println("Avalilable Catalogs ");
rs = dm.getCatalogs();
while(rs.next())
{
System.out.println("\tcatalog: "+ rs.getString(1));
}
rs.close();
rs = null;
closeConnection();
}
else System.out.println("Error: No active Connection");
}
catch(Exception e)
{
e.printStackTrace();
}
dm=null;
}
private void closeConnection()
{
try
{
if(con!=null)
con.close();
con=null;
}
catch(Exceptio n e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception
{
Connect myDbTest = new Connect();
myDbTest.displayDbProperties();
}
}


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: can't load java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriv Posted: Sep 25, 2006 12:42 AM
Reply to this message Reply
It looks like a classical classpath problem.
Your code looks good, I'm sure you can execute it from the compiler, right?
Try to print out your classpath variable during runtime (System.Properties ...)

Since I always set the classpath at program start I can't tell you if you have to put a '"' symbol at the start and the end of the classpath variable or to bring all entries to the 8.3 format.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: can't load java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriv Posted: Sep 25, 2006 12:44 AM
Reply to this message Reply
one more thing. When posting code here, please use the java tags as shown on the right side in the "formatting your post" section.
But: do NOT copy your old unformatted code into it but copy the code directly from your compiler.

Flat View: This topic has 2 replies on 1 page
Topic: Help please>< Previous Topic   Next Topic Topic: Mythical Man Month question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use