aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "use common-dbcp package Watch "use common-dbcp package New topic
Author

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();
Class.forName("com.mysql.jdbc.Driver");
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://localhost:3306");
ds.setUsername("root");
ds.setPassword("gaopass");
Connection conn=ds.getConnection();
PreparedStatement stmt=conn.prepareStatement("insert into blog values(?,?,?)");
stmt.setString(1,"asd");
stmt.setString(2,"dsa");
stmt.setString(3,"aaa");
stmt.execute();
stmt.close();
conn.close();



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(BasicDataSource.java:780)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at DT.main(DT.java:17)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)
... 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
Bartender

Joined: Oct 14, 2005
Posts: 18155
    
    8

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: http://aspose.com/file-tools
 
subject: use common-dbcp package's problem
 
Similar Threads
struts 2+jboss4.0.4+eclipse
Need Help regarding OpenEJB's error
database+struts
struts+database
connection pooling