my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes Properties file for DB connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Properties file for DB connection" Watch "Properties file for DB connection" New topic

Properties file for DB connection

Mahesh Lohi
Ranch Hand

Joined: Jun 22, 2009
Posts: 151
Hi all, I would like to use properties file to create connection to my mysql DB

My properties file

My Class file

Please let me know what the mistake is. I am getting an error like java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)

Thank you in advance
Karthik Jayachandran
Ranch Hand

Joined: Feb 18, 2009
Posts: 91

''@'localhost' (using password: YES)

You can see it is not getting the username and password

Have the url only separately.

And then add two more properties as,

It might work.
David Newton

Joined: Sep 29, 2008
Posts: 12617

This has nothing to do with Struts; moving.
Meena Rajani

Joined: Sep 03, 2014
Posts: 1
you have to change

Connection con =DriverManager.getConnection(url, username, password);

and pass following properties in file to the class

connectionurl = jdbc:postgresql://localhost:5432/test
I agree. Here's the link:
subject: Properties file for DB connection
It's not a secret anymore!