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

Getting database connection remotely

Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
Hi,

I am not sure if this is the right forum to ask this question, because it is related to JDBC/RMI/Core Java/ Swing.

Following is the problem.

In my application I need to get the connection remotely. I have web application and client application. client application is downloaded using the java web start/JNLP from the web server.

The client application also needs the database connection and do some operation on the database which is at web server.

I am planning to get connection remotely in this scenario so that i dont have to keep the JDBC URL information at client side.

I tried to get the connection remotely but go confused while implementing the RMI server interface of what to return and how i can get the registry setup only once and get the database connection each time i call the remote method.

Please help me out with this problem.

Regards,
Anant
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I don't think you have to implement to RMI or any distributed API for that, simply provide the IP address of the remote DB server in to the JDBC URL, like


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
Hi Sagar,

Thanks for the response.

Yes i agree that, i can just give the remote server URL but along with that i need to pass the username and password of the DB server. For security reason i need to hide these info from the client application. Hence I thought of RMI.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Sorry for not reading your requirement completely Somehow I missed this part of the post,
I am planning to get connection remotely in this scenario so that i dont have to keep the JDBC URL information at client side.

Anant Jagania wrote:For security reason i need to hide these info from the client application.

Well, I'm still stuck with my original plan, bacuase I'm not the RMI expert, but you can anytime cipher the user name and password and store it in the properties file, from where the original id & password can be deciphered.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
While using a proxy server (using RMI or some other technology) would be much preferable to using JDBC from a remote client because of security and architectural considerations, that doesn't solve the problem of access control: You still need to authenticate the client, and a username/password of some kind will likely be involved.

Sagar Rohankar wrote:you can anytime cipher the user name and password and store it in the properties file, from where the original id & password can be deciphered.

That doesn't really increase security, as now the encrypted username and password are the username and password - the user/client can find out about them, and use them to log into the system.


Ping & DNS - updated with new look and Ping home screen widget
Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
Okay... so now I am not sure what to do.. whether to use RMI or not...

Should put the username and password in properties file and that file belongs to jar file and obfuscate the jar file?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Anant Jagania wrote:Should put the username and password in properties file and that file belongs to jar file and obfuscate the jar file?

You should go with more experience thought here, as Ulf suggested.
Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
So I think I should go with proxy server and have interfaces with methods who can actually take the required parameters from the client and do the database operations on the server side.

The RMI Server interface/class will have to get database connection from server only and perform the database operations based on the data received from the client using the proxy objects.

Please correct me if I am wrong somewhere in this approach.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
whether to use RMI or not...

RMI is fine, as long as a) you're sure that client and server will always be in Java, b) that you can keep client and server JRE versions in synch, and c) that there won't be a firewall that blocks the RMI ports.

Because of these reasons I'd probably go with HTTP communication, maybe using a REST approach built on top of JAX-RS.

Should put the username and password in properties file and that file belongs to jar file and obfuscate the jar file?

Be aware that ultimately there's nothing you can do to protect client-side code. If the system becomes insecure if users know what happens inside of the client app, then it's not secure enough. I suggest to give each user their own username/password that they enter upon client application startup. Then you can send those alongside other data in the server calls.
Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
Hmmm... So I will have look into REST over JAX-RS. That will be new for me but it would be a good experience.

I got your point about Sending the User Credential along with any operation being performed on database. That sounds like a good plan and also good security.

Thanks Ulf and Sagar for helping me on this. I really appreciate it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting database connection remotely
 
Similar Threads
I need big help!!
java application MS Access
accessing database on server from a local machine as when required
web service client type
"Push" to the remote client Java application from server-side