A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Mongo DB Applied Patterns
this week in the
MongoDB
forum
or a resume review from
Five Year Itch
in the
Jobs Discussion
forum!
JavaRanch
»
Java Forums
»
Databases
»
JDBC
Author
Properties file for DB connection
Mahesh Lohi
Ranch Hand
Joined: Jun 22, 2009
Posts: 150
posted
May 29, 2010 11:42:26
0
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
Joined: Feb 18, 2009
Posts: 36
I like...
posted
May 30, 2010 23:52:46
0
''@'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
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Jun 01, 2010 06:04:37
0
This has nothing to do with Struts; moving.
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Properties file for DB connection
Similar Threads
Accessing variable from another method
how to upload pdf files to My sql with java
JDBC Exception in JNDI lookup
Help with this code!
jsp with servelet execution in tomcat
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter