Link to home
Start Free TrialLog in
Avatar of PowerMaxUK
PowerMaxUK

asked on

Java Applet - linking to my MS Access Database

have moderate skill level with java.
i have looked through the experts xchange for anything similar to my simple problem but they
all seem to be more advanced and confusing.

any help would be GREAT, thanks in advance!

enclose my simple code:

public class AppletDBaseTester extends JApplet
{
     static JLabel Header;
       static JButton EnterButton;
     public void init()
     {
     Header = new JLabel("link applet to dbase");
     EnterButton = new JButton("try");
     EnterButton.addActionListener(new DisplayResults());
     Container c = getContentPane();
     c.setLayout(new GridLayout(0,1));
     c.add(Header);
     c.add(EnterButton);
        }
     public static void DBase()
     {
     String URL = "jdbc:odbc:AppletTester";
     String username = "";
     String password = "";
     String[] EraseDBaseSQL =
     {     "Drop Table RoomTable"
     };
     try
     {
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     }
     catch (Exception e)
     {
     System.out.println("Failed to load JDBC/ODBC driver.");
     return;
     }
     Statement stmt = null;
     Connection con=null;
     try
     {
     con = DriverManager.getConnection (URL,username,password);
     stmt = con.createStatement();
     }
     catch (Exception e)
     {
     System.err.println("problems connecting to "+URL);
     }
     try
     {
     for (int i=0; i<EraseDBaseSQL.length; i++)
     {
     stmt.execute(EraseDBaseSQL[i]);
     }
     stmt.close();
        con.close();
     }
     catch (Exception e)
     {
     e.printStackTrace(System.out);
     System.err.println(EraseDBaseSQL);
     System.err.println("problems with SQL sent to "+URL+ ": "+e.getMessage());
     }
    }
}

class DisplayResults implements ActionListener
{
   public void actionPerformed(ActionEvent e)
   {
   AppletDBaseTester.DBase();
   }
}



i get the "Failed to load JDBC/ODBC driver" error


any ideas or am i going for the wrong idea... if someone has a few lines to help me :) thanks

Gareth
Avatar of girionis
girionis
Flag of Greece image

 Can you change this:

  System.out.println("Failed to load JDBC/ODBC driver.");

  to this:

  System.out.println("Failed to load JDBC/ODBC driver." + e);

  and let us know of the output?
Avatar of PowerMaxUK
PowerMaxUK

ASKER

returned following to console:

Failed to load JDBC/ODBC driver.java.security.AccessControlException: access den
ied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)


Gareth
I believe that to let applets have access to an ODBC data source, you'd either have to configure no (or low) security at the client's VM, or digitally sign your applet.

brian

There are four different kind of drivers for JDBC, the JDBC/ODBC is a type 1 driver and as mentioned is restricted to signed applets. You may want to go to microsofts netpages and download type 4 driver wich is faster driver. You should generally be aware of the restrictions that an applet has when using JDBC, go here for a quick overview: http://www.sybase.com/detail/1,6904,1000696,00.html

 As mentioned above you will either need to sign your appelt or give permissions to it manually. If you want to do it manually just edit the java.policy file and add the RuntimePermission. If you want to sign the applet look here:

  http://www.ddj.com/articles/1999/9902/
  http://java.sun.com/security/signExample/index.html
the idea is so i can run my webpage/applet on a network pc. so i dont know if i can but i dont really want to go throught the process of setting permissions on everyones java.policy file. im sure that would take a long time as there is many computers. what would the line be to set the permissions in the policy file?
i want to do it on mine to make sure it all works ok for a start.
then what does everyone suggest i do? would there just be a few lines to add to my code that will sign it without mass effort for every user?

many mnay mnay thanks

Gareth
 Then you will need to sign the applet I am afraid. You only have to sign it once and then it will eb done automatically on every computer that tries to access it.

  And I'd also suggest you use type 4 drivers since type 1 (that is JDBC/ODBC bridge) require every single user to have a datasource configured on their computer, therefore you will have to manualyl configure the database source on every client machine.
ok so i get type 4 drivers and i sign the applet.

i know there are links above but any clue where to get the driver from or even a slightly less complicated example of signing an applet... i will go look myself, being lazy.

any help would be appriciated tho :)
thanks
G
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i tried that drivers page, it came up with 2 driver locations both the same

http://www.bcs-corp.com/download.shtml

and the driver isnt there :/

will driver 3 be ok?
 Yes it will probably be fine. If in doubt read the documentation.
ok, thanks for all the help... think its well on the way to running i hope :) have enough info now! :)

thanks all

gerionis i will accept one of your answers... does it matter which one?

thanks

Gareth
 No it doesn't but I suggest you accept a relevant one so other people might be helepd as well :-)
Thanks very much!

gareth
 Thank you :-)