Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JDBC in Applets, problems

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found code for DB Connectivity in Java Apps but I haven't found any Applet specific ones. Are there any special DB related additions I must include in applet code for it to work?
I ask this because I'm trying to connect to a mysql db from an applet and my applet will print only as far as "Attempting a connection..." and then will not print out any of the SQL table. My code looks like this:
import java.sql.*;
import java.applet.Applet;
import java.awt.*;
public class DBConnectApplet1 extends Applet {
public void paint(Graphics g) {
//try to load JDBC driver
g.drawString("Attempting to load driver...",0,0);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
g.drawString("Driver Found",100,0);
}
catch(ClassNotFoundException ee) {
ee.printStackTrace();
g.drawString("Driver Not Found",100,0);
}
//attempt to establish connection with database
String url = "jdbc:mysql://localhost/thedew";
String user = "guest";
String password = "";
Connection con = null;
// open connection
try {
g.drawString("Attempting a connection...",0,50);
con = DriverManager.getConnection(url, user, password);
g.drawString("Connection Established",100,50);
}
catch(SQLException e) {
e.printStackTrace();
g.drawString("Connection Failed",100,50);
}
//issue SQL statements...
Anyone have ideas about why this is so. I've read that replacing localhost with your ip address works but it didn't seem to make a difference with me. Thanks.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too had the same problem. What I did was that i used the classes11.zip in the same directory as of the html file and also added the classes11.zip in the html page. The applet requires (as I got my code working) classes11.zip to be downloaded on the client side.
 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like to put a servlet in between the two. That works fine, as I let the applet talk to the servlet and the servlet does all the talking to MySQL.
    Bookmark Topic Watch Topic
  • New Topic