Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Connection Password?

 
Paul Brabban
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is my first post so apologies if I get anything wrong. I'm Paul from the UK, joined up here after reading about it in one of Kathy Sierra's study guides.

I have a question about good practise in connecting to databases via JDBC. If I have a simple program running that connects to a database, it needs a username/password to do so.

What is the most secure and flexible way to make a username/password combination available to the program? Sorry if it's obvious and I should know it!

Thanks everyone!
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a command line tool, use one of the java.io.Console.readPassword methods to read the password:


If it's a graphical user interface, use a JTextField and a JPasswordField:
 
Paul Brabban
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that, but I was meaning more in the case of unattended operation - a server daemon for example. If there isn't a person around to put in a password, what's the best way of storing that password so that I can get to it and use it to connect to my database?

Thanks,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
You can put it in a property file. For more security, you could encrypt it. You could also put it in a directory with limited read permissions.
 
Paul Brabban
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for your advice, good to know that there isn't a simple gee-whiz solution that I missed!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic