• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet to Database connection

 
neeraj
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
 
Tom P
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.
 
Swapan Golla
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.
 
Anonymous
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 !!!
 
paul wheaton
Trailboss
Pie
Posts: 21673
Firefox Browser IntelliJ IDE 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.
 
Keyur Shah
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.
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic