Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Applet to Database connection  RSS feed

 
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: 22837
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.
 
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
Boost this thread!