File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Applet to Database connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet to Database connection" Watch "Applet to Database connection" New topic
Author

Applet to Database connection

neeraj
Greenhorn

Joined: Feb 18, 2000
Posts: 10
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

Joined: May 06, 2000
Posts: 88
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

Joined: May 31, 2000
Posts: 32
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Dec 14, 1998
Posts: 20639
    ∞

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.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Keyur Shah
Greenhorn

Joined: May 31, 2000
Posts: 15
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.
------------------
 
 
subject: Applet to Database connection