File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes my applet can't connect to database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "my applet can Watch "my applet can New topic
Author

my applet can't connect to database

liana lim
Greenhorn

Joined: Oct 12, 2008
Posts: 8
my applet can't connect to my mysql database. i put my applet class and database in 1 server.

i use this code to connect the database




and here's the error


can anyone tell me how to fix it??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
Applets are only allowed to connect to the server they were served from. If the database is on some other server, then the applet needs to be signed. See HowCanAnAppletReadFilesOnTheLocalFileSystem for more detail.
liana lim
Greenhorn

Joined: Oct 12, 2008
Posts: 8
i already did it. my applet and my database are on same server
liana lim
Greenhorn

Joined: Oct 12, 2008
Posts: 8
I already add java policy on client side with this :

grant codeBase "http://192.168.71.50/-" {
permission java.security.AllPermission;
};

it still can't connect database. help please....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
Policy files can be tricky. Make sure that the one you're making changes to is really being used.

As an aside, you should remove the ".newInstance()" call in the driver initialization.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

There could also be a firewall issue.

Look back in the forum archives about 2 weeks and I've covered this before. Including a rant why most applets have no business operating in 2-tier mode and opening their own JDBC connections.


Customer surveys are for companies who didn't pay proper attention to begin with.
atul anand
Greenhorn

Joined: Oct 25, 2008
Posts: 5
grant {
permission java.lang.RuntimePermission
"accessClassInPackage.sun.jdbc.odbc";
permission java.util.PropertyPermission
"file.encoding", "read";
};

save this to txt file say ... grantacc.txt


and to command prompt write this'

appletviewer -J-Djava.security.policy=grantacc.txt ur_file.html


scjp 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: my applet can't connect to database