Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting an SQLException trying to use JDBC with applet

Status
Not open for further replies.

JediAnt1105

Programmer
Aug 13, 2003
3
0
0
GB
Hi everyone.
I'm trying use an applet to communicate with a Microsoft Access database using JDBC. The program runs fine as an application, but when I change it to an applet and run it with AppletViewer, it gives me the following exception:

Exception:
----------

Initialising...
starting...
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:537)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at PcBuddyApplet.ConnectToDB(PcBuddyApplet.java:44)
at PcBuddyApplet.start(PcBuddyApplet.java:16)
at sun.applet.AppletPanel.run(AppletPanel.java:358)
at java.lang.Thread.run(Thread.java:484)

The applet code is as follows:
------------------------------

import java.sql.*;
import java.applet.Applet;
import java.awt.Graphics;

public class PcBuddyApplet extends Applet{

StringBuffer buffer;

public void init(){
buffer = new StringBuffer();
addItem("Initialising...");
}

public void start() {
addItem("starting... ");
ConnectToDB();
}

public void stop() {
addItem("stopping... ");
}

public void destroy() {
addItem("preparing for unloading...");
}

void addItem(String newWord) {
System.out.println(newWord);
buffer.append(newWord);
repaint();
}

public void paint(Graphics g) {
//Draw a Rectangle around the applet's display area.
g.drawRect(0, 0, size().width - 1, size().height - 1);

//Draw the current string inside the rectangle.
g.drawString(buffer.toString(), 5, 15);
}

public void ConnectToDB(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:eek:dbc:pCBUDDY");
Statement stmt = conn.createStatement();
String query = "Select * from Users";
ResultSet rs = stmt.executeQuery(query);
addItem("\nUsername \tPassword \tEmail Address");
while(rs.next()){
addItem("\n" + rs.getString(1) + "\t " + rs.getString(2) + "\t" + rs.getString(3));
}
rs.close();
rs = null;
}
catch(ClassNotFoundException c){
c.printStackTrace();
}
catch(SQLException s){
s.printStackTrace();
}
}
}

Can anyone help me please? I have looked on the web, but I cannot find the source of this problem. Thanks in advance!
 
Try using the JDBC Trace Utility

DriverManager.setLogWriter( new PrintStream(System.out));

-pete
 
Thanks palbano.
I now get this error log before the exception:
-----------------------------------------------


Initialising...
starting...
DriverManager.getConnection("jdbc:eek:dbc:pCBUDDY")
trying driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcD
river@26804e]
getConnection: no suitable driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:537)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at PcBuddyApplet.ConnectToDB(PcBuddyApplet.java:46)
at PcBuddyApplet.start(PcBuddyApplet.java:17)
at sun.applet.AppletPanel.run(AppletPanel.java:358)
at java.lang.Thread.run(Thread.java:484)

It seems as though the driver is not suitable for .mdb databases. However the very same driver works if I run the code as an application and not an applet. Is there a different driver that anyone can suggest? Any help would be appreciated - thanks everyone.
 
I have solved the problem by upgrading to jdk 1.4.
It seems the ODBC driver in 1.3 did not work properly, or maybe it was just the reinstallation that did it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top