java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

Hi, I get the error in the subject when I use it with the following code in an applet.

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connection = DriverManager.getConnection(url, username, password); }

catch (Exception e) {

e.printStackTrace();

name.setText(e.toString());

connection = null;

}

where url, username, and password are correct and "name" is a textfield which I use in this portion for debugging purposes. Is the problem because of the applet structure, that is, applet cannot access a database on the system, or because of the non-existence of a class? I think the necessary classes is present with the JDK1.3.1 which ? am using. So what is the problem, could someone please help me?

[772 byte] By [marikkan] at [2007-9-26 1:17:39]
# 1

When you want to dynamically load a class from the applet , it is only logical that it should be loaded from the server as there is no gurantee that JDBC driver class will be in the client. You should provide the codebase attribute in your applet tag to load the class from the server. Exact syntax I don't remember.

However... I don't think this would solve your problem. Though I have little experience in Applets, I feel your applet must use a RMI JDBC driver to connect to the database, instead of JDBC-ODBC bridge.

Anyone who knows more about these may help you better.

shubhrajit_c at 2007-6-29 0:47:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

I also forgot to tell the type of the database if that would help. The database is an Microsoft Access 2000 database which has been added to the DSN by ODBC-32 bit data sources. Maybe, JDK could also have some problems with the above parameters of which I am not aware.

Another important issue is that I also developed some servlets on this very machine using the JDBC-ODBC bridge (the same way as my original code), and there was not any problems about it.The database was an Oracle database if that would help. Maybe, to connect to a database via an applet, I need something else (because of security reasons) of which I am unaware at the moment. Thanks for your attention.

marikkan at 2007-6-29 0:47:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

i get the same problem and would like my applet to store and retrieve data from a MS acess 2000 database. but it lways throws that same exception

if u have any ideas please can u help

> I also forgot to tell the type of the database if that

> would help. The database is an Microsoft Access 2000

> database which has been added to the DSN by ODBC-32

> bit data sources. Maybe, JDK could also have some

> problems with the above parameters of which I am not

> aware.

> Another important issue is that I also developed some

> servlets on this very machine using the JDBC-ODBC

> bridge (the same way as my original code), and there

> was not any problems about it.The database was an

> Oracle database if that would help. Maybe, to connect

> to a database via an applet, I need something else

> (because of security reasons) of which I am unaware at

> the moment. Thanks for your attention.

kingfahad786 at 2007-6-29 0:47:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

how did you specify the URL to your DriverManager? I have a piece of code that works and I didn't add it in the DSN. I just specified the absolute path of the Microsoft Access Database (*.mdb).

I'm also using sun.jdbc.odbc.JdbcOdbcDriver and Access 2000.

try this:

StringBuffer buffer = new StringBuffer("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=");

buffer.append("C:\temp\sample.mdb");

String url = buffer.toString();

deandaniel at 2007-6-29 0:47:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
would it work just by using this piece of code, what about all those security restrictions assocaiated with applets and connecting to an database on yr own machine.
kingfahad786 at 2007-6-29 0:47:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

is it possible to give the whole code associated with he way u connect to the database, im not sure what to do with this code u have given,is it just needed to specify the url and still use the rest of the code to connect to that database

> how did you specify the URL to your DriverManager? I

> have a piece of code that works and I didn't add it in

> the DSN. I just specified the absolute path of the

> Microsoft Access Database (*.mdb).

>

> I'm also using sun.jdbc.odbc.JdbcOdbcDriver and Access

> 2000.

>

> try this:

>

> StringBuffer buffer = new

> StringBuffer("jdbc:odbc:Driver={Microsoft Access

> Driver (*.mdb)};DBQ=");

> buffer.append("C:\temp\sample.mdb");

> String url = buffer.toString();

kingfahad786 at 2007-6-29 0:47:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

Applets does not have a permission to access the database.If you try to access database thorugh an applet it throws security exception.

What you can do is write a servlet, an applet and a middleclass to access that servlet and in the servlet you can write the JDBC code.It will work.

aparna_chitragar at 2007-6-29 0:47:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

To access this class from an applet you need to have some security permissions. In short, configure your navigator/explorer to give trusted state to your domain.

Remenber that you are using a JDBC driver that needs his pair, an ODBC DSN, which have to be configured in each client.

It will be different if you use a JDBC driver that can be included in your applet (the ODBC bridge can't), then no security permissions are involved in loading the driver.

llturro at 2007-6-29 0:47:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...