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.addActionListe ner(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.od bc.JdbcOdb cDriver");
}
catch (Exception e)
{
System.out.println("Failed to load JDBC/ODBC driver.");
return;
}
Statement stmt = null;
Connection con=null;
try
{
con = DriverManager.getConnectio n (URL,username,password);
stmt = con.createStatement();
}
catch (Exception e)
{
System.err.println("proble ms 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.o ut);
System.err.println(EraseDB aseSQL);
System.err.println("proble ms with SQL sent to "+URL+ ": "+e.getMessage());
}
}
}
class DisplayResults implements ActionListener
{
public void actionPerformed(ActionEven t 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
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.addActionListe
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.od
}
catch (Exception e)
{
System.out.println("Failed
return;
}
Statement stmt = null;
Connection con=null;
try
{
con = DriverManager.getConnectio
stmt = con.createStatement();
}
catch (Exception e)
{
System.err.println("proble
}
try
{
for (int i=0; i<EraseDBaseSQL.length; i++)
{
stmt.execute(EraseDBaseSQL
}
stmt.close();
con.close();
}
catch (Exception e)
{
e.printStackTrace(System.o
System.err.println(EraseDB
System.err.println("proble
}
}
}
class DisplayResults implements ActionListener
{
public void actionPerformed(ActionEven
{
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
ASKER
returned following to console:
Failed to load JDBC/ODBC driver.java.security.Acces sControlEx ception: access den
ied (java.lang.RuntimePermissi on accessClassInPackage.sun.j dbc.odbc)
Gareth
Failed to load JDBC/ODBC driver.java.security.Acces
ied (java.lang.RuntimePermissi
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
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
http://www.ddj.com/articles/1999/9902/
http://java.sun.com/security/signExample/index.html
ASKER
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
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.
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.
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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.
ASKER
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
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 :-)
ASKER
Thanks very much!
gareth
gareth
Thank you :-)
System.out.println("Failed
to this:
System.out.println("Failed
and let us know of the output?