aspose file tools*
The moose likes Applets and the fly likes JApplet not connecting to SQL database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "JApplet not connecting to SQL database" Watch "JApplet not connecting to SQL database" New topic
Author

JApplet not connecting to SQL database

Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
Hey all,

I am trying to get data from a SQL database through an applet so that i can put it on a website. I have put literally the same code in a normal class that uses main as in a class that extends JApplet, and it works fine for the normal class, but the applet cannot connect.

Both seem ot load the driver, but for the applet thats as far as it goes. After thatit give a ExceptionInInitializerError

Here is the code I used:
the class that works first:



and then the applet code:


thanks for your help
Andrew
Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
and please disregard


that was a class I made for the real project that is not used in my tests
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

You'll find that

is more useful, since it tells you much more than just the name of the exception.
Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
Thanks Paul, I changed it.

Still though, it always points to this line of code:


Any ideas?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Yes, I have ideas. But my suggestion was designed to get you to look at the stack trace. Apparently you only looked at the line number where the error came from. Look at the whole stack trace.

If you have questions about it, post it.
Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
Ok thanks Paul,

I think I understand it better possibly. it looks like there is a problem with the driver I am using when it parses the URL since DriverManager seems to call methods in the jTDS driver that call the parseURL() method. Does this sound right?

here's the stack trace:


And you're right, I was just looking at the line in my code that was in the stack.
thanks,
Andrew
Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
Actually it looks like the AccessControlContext.checkPermission() method is thowing a AccessControlException, which is probably why the Applet won't connect to the database. Is there anyway to ignore that exception or get permission?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Right, that's what I expected. Insecure applets aren't allowed to connect to any server except the one they were loaded from. The way to give them permission to do that is to sign the applet.
Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
Thanks again Paul for sticking with me through this. So I looked up signing Java Applets, and I found out how to do it from the command line, but just to make sure, could you tell me if I'm doing this correctly?

I placed TestApplet.java in a new folder(I called Test), then made a keystore (don't know if that's the correct term), then packed the folder into a jar file (test.jar), then signed the jar file using jarsigner.

So not only do I not know if that is right, I also really don't know where to go from there. how do i run the Applet?

Thanks,
Andrew
Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
I have signed the jar file and run it from a .htm file. I put in a JOptionPane message that lets me know when the applet starts, and it does, but the SQL data is still not accesed
Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
I have figured out why. The Java Console now says that driver class cannot be found, which has been accessable from the file when it was not in the .jar

the Driver's jar file is in my classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JApplet not connecting to SQL database