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

MSAccess and Applet

0 views
Skip to first unread message

Walid

unread,
Nov 10, 2000, 3:00:00 AM11/10/00
to
I am trying to access a database from a java applet. When I tray to use the
following code :
import java.sql.*;

class MSAccTest
{
public static void main(String[] args)
throws SQLException, ClassNotFoundException {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dsn = "jdbc:odbc:data";
String user = "admin";
String password = "";
String sql = "select * from activity";

Connection con = DriverManager.getConnection(dsn, user, password);
String sql = "CREATE TABLE tblTest (val1 TEXT, val2 TEXT)";

Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
}
};

It works fine. When I try to use the same code (similar) in a java Applet
it will not work.. the data base is in the same computer that the applet is
started in. I am using windows 98. The code is:

public void CreatTable(String name){

statment ="SELECT * from activity WHERE barCode="+name+";";
Connection con =null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dsn = "jdbc:odbc:data";
String user = "admin";
String password = "";
String sql = "CREATE TABLE"+ name+" (val1 TEXT, val2 TEXT)";

con = DriverManager.getConnection(dsn, user, password);

Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
}
catch (ClassNotFoundException e) {
label13.setText("Class not found");
e.printStackTrace();
}
catch (SQLException e){
label13.setText("Error in creat");
}


}
I get the following error

Exception occurred during event dispatching:
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 data_access.getItemDetails(data_access.java:821)
at data_access.button21ActionPerformed(data_access.java:779)
at data_access.access$1(data_access.java:778)
at data_access$2.actionPerformed(data_access.java:765)
at java.awt.Button.processActionEvent(Button.java:329)
at java.awt.Button.processEvent(Button.java:302)
at java.awt.Component.dispatchEventImpl(Component.java:2595)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
at
java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
Can any body help


Brad Webb

unread,
Nov 12, 2000, 3:00:00 AM11/12/00
to

Hello,
I guess you noticed that Java said you violated the applet security rules.
Applets cannot directly initiate a JDBC query. They can talk to an application
via a socket which in turn submits the query and returns the result.
Brad Webb

Walid

unread,
Nov 13, 2000, 3:00:00 AM11/13/00
to
I have done the following:
1- in the connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();

con = DriverManager.getConnection(dsn, user, password);
2- I have used policytool to generate the following:
grant {
permission java.security.AllPermission;
};
and saves it in the windows directory as .java.policy
3- I have used html convert to convert the applet


Walid

unread,
Nov 13, 2000, 3:00:00 AM11/13/00
to
It is working now ..:)

0 new messages