wood burning stoves 2.0*
The moose likes JDBC and the fly likes JDBC Connection Password? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connection Password?" Watch "JDBC Connection Password?" New topic
Author

JDBC Connection Password?

Paul Brabban
Ranch Hand

Joined: Jan 13, 2008
Posts: 44
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!


"The important thing is not to stop questioning."
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Brabban
Ranch Hand

Joined: Jan 13, 2008
Posts: 44
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Paul Brabban
Ranch Hand

Joined: Jan 13, 2008
Posts: 44
Thank you both for your advice, good to know that there isn't a simple gee-whiz solution that I missed!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Connection Password?
 
Similar Threads
JSP to Access 2000 database
Retrieve DB2 credentials configured on websphere
JDBC Connections Freezing with Multiple Users Accessing DB
Transfer Huge data using Java
Conditional Redirecting using JSP