?
Solved

Java Applet - linking to my MS Access Database

Posted on 2003-03-09
15
Medium Priority
?
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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