• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting database connection remotely

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Anant Jagania
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anant Jagania
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic