This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes use common-dbcp package's problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "use common-dbcp package Watch "use common-dbcp package New topic

use common-dbcp package's problem

gao zhixin
Ranch Hand

Joined: Jan 18, 2006
Posts: 42
this is a fragment of code:

BasicDataSource ds=new BasicDataSource();
Connection conn=ds.getConnection();
PreparedStatement stmt=conn.prepareStatement("insert into blog values(?,?,?)");

and these are Exception throws from console:

Exception in thread "main" org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql://localhost:3306'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(
at org.apache.commons.dbcp.BasicDataSource.getConnection(
at DT.main(
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(
... 2 more

why ???
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Most probably, the driver java is not in the classpath being used at execution time.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Or perhaps the problem is that you didn't specify the name of the database in your JDBC URL.
gao zhixin
Ranch Hand

Joined: Jan 18, 2006
Posts: 42
the problem solved, I forgot to tell the Driver the database I use. It's a shame to ask the problem like this...
I agree. Here's the link:
subject: use common-dbcp package's problem