This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes Using Commons dbcp with MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using Commons dbcp with MySQL" Watch "Using Commons dbcp with MySQL" New topic
Author

Using Commons dbcp with MySQL

Sachin Dere
Ranch Hand

Joined: Jan 14, 2003
Posts: 80
Hi guys,
how can i use Commons DBCP with MySQL DB?All the examples are using Oracle Driver.How do i set the username & pwd for it?
pls help me,
thanks,
Sachin
Yashar Kalantari
Greenhorn

Joined: Sep 19, 2004
Posts: 12
Hi Sachin

I am declaring my solution acording to sample in URL

http://cvs.apache.org/viewcvs.cgi/jakarta-commons/dbcp/doc/ManualPoolingDriverExample.java?rev=1.6&view=markup

you can change your Driver by changing the Driver package like this

System.out.println("Loading underlying JDBC driver.");
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

it's abvioues that befor doing this you need to download this driver from mysql website and deploy it.

for passing username and password to DBCP try this:

Properties props = new Properties();
props.put("user", "username");
props.put("password", "password");

ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(this.getDbURL(), props);

regards yashar.

[ November 25, 2004: Message edited by: Yashar Kalantari ]

[ November 25, 2004: Message edited by: Yashar Kalantari ]
[ November 25, 2004: Message edited by: Yashar Kalantari ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Commons dbcp with MySQL