• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JApplet not connecting to SQL database

 
Andrew Cho
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and please disregard


that was a class I made for the real project that is not used in my tests
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll find that

is more useful, since it tells you much more than just the name of the exception.
 
Andrew Cho
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, I changed it.

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


Any ideas?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic