Database connection issue...
I have been writing a distributed application in Java. Originally, the code used to access a remote database from a client machine using JDBC to retrieve data. I tried to implement the database access in RMI, i.e. there is one DatabaseManager object that is running on the server that controls access to the database. However, I have been unsuccessful in getting the program to work using RMI. When I run the program on the server, I get the following messages:
-------------------------------------------------------------------------------------------------------------------
root@server:~# java entnet.server.DatabaseManager
Unable to connect to database at present. Click "OK" to return to main menu.
java.sql.SQLException: Unable to connect to any hosts due to exception: java.security.AccessCont********************ception: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
ComputeEngine exception: java.security.AccessCont********************ception: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
root@server:~# java entnet.server.DatabaseManager
Unable to connect to database at present. Click "OK" to return to main menu.
java.sql.SQLException: Unable to connect to any hosts due to exception: java.security.AccessCont********************ception: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
DatabaseManager exception: java.security.AccessCont********************ception: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
-------------------------------------------------------------------------------------------------------------------
The first error is the DatabaseManager object attempting to connect to the local database. Obviously, it's access has been denied. This only happened when I tried to access the database locally, I was able to connect to the database fine from a remote machine.
The second error is java trying to register my remote class with the rmiregistry.
I am not too sure, but I think that what I need is to create a custom policy file that grants access to these interfaces and ports. Can somebody give me a little help as I have not had any previous experience dealing with Java's security mechanism. Am I correct about the policy file? If so, how to I specify to the JVM that it should use the new policy file?
Any help will be most appreciated.
Thank you.
Peter Green.
|