• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Applet to Database connection

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to get values from the database and show it on the applet. I am attaching the code for connecting the database. It is giving Security Exception Error
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.table.TableColumn;
import java.sql.SQLException;
import java.sql.*;
import java.applet.Applet;
public class TablePanel extends Applet {
public void init() {
// setLayout (new BorderLayout());
try
{
Connection con = null;
Statement stmt = null;
Statement stmt1 = null;
ResultSet rs = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = java.sql.DriverManager.getConnection("jdbc dbc ubs","sa","sa");

stmt = con.createStatement();
String sQuery = "select * from w_users";
rs = stmt.executeQuery(sQuery);
rs.next();

}
catch(SQLException ex)
{
System.out.println("Error");
}
catch(ClassNotFoundException ex)
{
System.out.println("Class not found");

}

}
}
Pls suggest me how to do this.
Thanks in advance
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't connect to a database server unless the applet came from the same server. The browser simply won't let that happen unless you have a certificate and the user gives permission.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other way of solving this thing is to connect the database using a servlet and get all the results and then feed the output stream to the applet. The applet-servlet communication chapter in Jason Hunter's Servlet Programming book helps a lot.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Tom P:
You can't connect to a database server unless the applet came from the same server. The browser simply won't let that happen unless you have a certificate and the user gives permission.


Can I connect to the same server from where the applet is loaded ? i.e. can I create a socket to the server from where the applet is loaded ? I've read this many times.. but its not working !!!
 
Trailboss
Posts: 23194
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your applet is allowed to talk to the server that the applet was loaded from.
If your database is on that machine, you'll be fine. It sounds as if that is not currently the case.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to connect to the database(MS Access) which is on the same web-server (Microsoft's personal web server)- but it doesn't work with IE5.
------------------
 
Are you here to take over the surface world? Because this tiny ad will stop you!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic