JediAnt1105
Programmer
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("jdbcdbcCBUDDY"
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!
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("jdbcdbcCBUDDY"
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!