Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DB access

0 views
Skip to first unread message

Darius Blaszijk

unread,
Oct 6, 2000, 3:00:00 AM10/6/00
to
Hello,

I would like to use the JDBCAdapter class that is included in the demo apps
with JDK1.3. TableExample2 is an example app. that shows how to use it. I
have copied the source but I cannot get it to run as an applet. I get the
message : AccessControlException.
I guess that the applet hasn't got permission to access the DB through ODBC,
but how can I give it the right permission??!! Or do I have to alter the
source??

To be sure that all relevant information is given, I have included the
complete error message and the examplary sourcode I am using.

Tanks a lot for any help, Darius Blaszijk

/*-------------------- here comes the source

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.*;
import javax.swing.*;

public class Test extends JApplet
{
JPanel pnlTable = new JPanel();
String strDNS = "Mydb";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String URL = "jdbc:odbc:" + strDNS;
String query ="SELECT * FROM MyTable";
String user = "sa";
String passwd = "";

public void init()
{
JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd);
dt.executeQuery(query);
JTable tblView = new JTable(dt);
JScrollPane scrpTable = new JScrollPane(tblView);
scrpTable.setPreferredSize(new Dimension(700, 300));
getContentPane().setLayout(new BorderLayout());
getContentPane().add("Center",scrpTable);
scrpTable.setPreferredSize(new Dimension(300, 50));
}
}

/*-------------------- end of the source

/*-------------------- error message

java.security.AccessControlException: access denied
(java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java
:272)
at
java.security.AccessController.checkPermission(AccessController.java:399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1501)
at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:169)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:105)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at JDBCAdapter.<init>(JDBCAdapter.java:54)
at Test.init(Test.java:19)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)

/*-------------------- end of error message


Chris Smith

unread,
Oct 6, 2000, 3:00:00 AM10/6/00
to
Darius Blaszijk <DBla...@ZonNet.nl> wrote ...

> I would like to use the JDBCAdapter class that is included in the demo
apps
> with JDK1.3. TableExample2 is an example app. that shows how to use it. I
> have copied the source but I cannot get it to run as an applet. I get the
> message : AccessControlException.
> I guess that the applet hasn't got permission to access the DB through
ODBC,
> but how can I give it the right permission??!! Or do I have to alter the
> source??

Look up applet signing on the web... or in the Java Programmer's FAQ at
http://www.afu.com/intro.html for more information on granting privileges.
Some concerns though:

1. The ODBC bridge is part of the sun.* classes provided with the JDK. It
is not included with the Java runtimes in popular browsers. So you'll need
to use the Java plug-in at a minimum, and just hope that because most people
who install the plug-in are using the Sun plug-in, the ODBC bridge is
probably there.

2. There are severe disadvantages anyway to using JDBC directly from an
applet in most cases... such as:

2a) If you give the applet any security tokens (passwords, keys, et cetera)
then your security is shot. Otherwise, your users need to know your
database password to access the database.

2b) If you switch databases, you'll need to find new ways of shoehorning
JDBC drivers into your applet. That change can't just be made with server
side code. Using servlets is a very good way to separate business logic
from the GUI... applets should really not know about business logic if you
can avoid it, except for trivial programs like a menu applet.

I would suggest that unless you have no way of doing this, you always use
some server side technology for database access. Servlets work fine for
this. Perl scripting with CGI would also work if you don't want to write
servlets.

Chris Smith

0 new messages