File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Commons dbcp with MySQL

 
Sachin Dere
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic