Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
JDBC and Relational Databases
Properties file for DB connection
Mahesh Lohi
Ranch Hand
Posts: 151
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all, I would like to use properties file to create connection to my mysql DB
My properties file
driver=com.mysql.jdbc.Driver connectionurl = jdbc:mysql://localhost:3306/itruth?" + "user=root&password=123456
My Class file
public class Connect { static public void main(String argv[]) throws FileNotFoundException, IOException, ClassNotFoundException, SQLException { String url; String driv; Properties props = new Properties(); props.load(new FileInputStream("Hello.properties")); Class.forName("com.mysql.jdbc.Driver"); url = props.getProperty("connectionurl"); System.out.print(url); ResultSet rs = null; String connectionur=url; Connection con =DriverManager.getConnection(url); PreparedStatement stm=con.prepareStatement("select * from filename"); rs=stm.executeQuery(); while(rs.next()) { System.out.println(rs.getString(1)); } // System.out.println(message); } }
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
Posts: 93
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
''@'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,
username=root password=123456
It might work.
David Newton
Author
Posts: 12617
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This has nothing to do with
Struts
; moving.
Meena Rajani
Greenhorn
Posts: 1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
you have to change
Connection con =DriverManager.getConnection(url, username, password);
and pass following properties in hello.properties file to the class
driver=org.postgresql.Driver
connectionurl =
jdbc
:postgresql://localhost:5432/test
username=xxxxxx
password=xxxxx
How do they get the deer to cross at the signs? Or to read this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JDBC Exception in JNDI lookup
jsp with servelet execution in tomcat
how to upload pdf files to My sql with java
Accessing variable from another method
Help with this code!
More...