• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to avoid hardcoded password and username in JDBC connection

 
Shakuntala Bhajantri
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

i am new to java ,i am trying some example on JDBC but if i want to connect to database i need to mention username and password of my database so ,how to avoid hardcoded password and username in JDBC connection
 
Jon Avadis
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could read those values from a file, or you could prompt the user with a console or graphic user interface (GUI).
 
Vijay Tidake
Ranch Hand
Posts: 146
Hibernate Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If developing the web application ,write the in the web.xml as <context-param>

Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Can you put them into your database with the password() function? That stores a hash, which you can't reconstruct the password from.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you misunderstood. Shakuntala is talking about the username / password to use to connect to the database in the first place.

They need to be stored in some external way; a resource file inside the JAR file, a configuration file (preferably using XML or java.util.Properties), the Windows registry (using a third party library or java.util.prefs.Preferences), etc.
 
Ashish Bassi
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eventually in order to make it configurable, password must be in some properties/xml file. I suggest you can keep it in an encoded form in a properties file. You can decode the same in your Java code while making a DB connection
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I had the wrong password. Sorry.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic