Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Java Applet - linking to my MS Access Database

Posted on 2003-03-09
15
Medium Priority
?
215 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:PowerMaxUK
15 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8099338
 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?
0
 

Author Comment

by:PowerMaxUK
ID: 8099434
returned following to console:

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


Gareth
0
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8100676
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:RayGun
ID: 8101403

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

0
 
LVL 35

Expert Comment

by:girionis
ID: 8101788
 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
0
 

Author Comment

by:PowerMaxUK
ID: 8102244
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
0
 
LVL 35

Expert Comment

by:girionis
ID: 8102359
 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.
0
 

Author Comment

by:PowerMaxUK
ID: 8102383
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
0
 
LVL 35

Accepted Solution

by:
girionis earned 400 total points
ID: 8102516
 You can get the drivers from here:

  http://industry.java.sun.com/products/jdbc/drivers

  each database has different drivers.

  Signign applets:

  http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20060040.html
0
 

Author Comment

by:PowerMaxUK
ID: 8102534
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?
0
 
LVL 35

Expert Comment

by:girionis
ID: 8102593
 Yes it will probably be fine. If in doubt read the documentation.
0
 

Author Comment

by:PowerMaxUK
ID: 8102705
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
0
 
LVL 35

Expert Comment

by:girionis
ID: 8103078
 No it doesn't but I suggest you accept a relevant one so other people might be helepd as well :-)
0
 

Author Comment

by:PowerMaxUK
ID: 8103105
Thanks very much!

gareth
0
 
LVL 35

Expert Comment

by:girionis
ID: 8103122
 Thank you :-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question