Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 46021 invoked from network); 27 Jun 2003 10:57:50 -0000 Received: from imail.accnorwalk.com (64.186.197.63) by daedalus.apache.org with SMTP; 27 Jun 2003 10:57:50 -0000 Received: from veleba.net [64.186.207.32] by imail.accnorwalk.com with ESMTP (SMTPD32-8.00) id A18AC1D011E; Fri, 27 Jun 2003 06:50:50 -0400 Date: Fri, 27 Jun 2003 06:57:49 -0400 Subject: Re: no suitable driver when using DBCP Content-Type: text/plain; delsp=yes; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v552) From: Keith Veleba To: "Jakarta Commons Users List" Content-Transfer-Encoding: 7bit In-Reply-To: <002c01c33c4e$1b173fd0$6a00a8c0@Animal> Message-Id: <317F380A-A88E-11D7-B4C1-00039398EA86@veleba.net> X-Mailer: Apple Mail (2.552) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Having it in the CLASSPATH and the system properties isn't enough. You also have to call DriverManager.registerDriver() for the driver you want to use. On Thursday, June 26, 2003, at 09:47 PM, Clark D. Richey, Jr. wrote: > When using the following code I get this error: > > org.apache.commons.dbcp.DbcpException: java.sql.SQLException: No > suitable driver > > I have the jar file with the mysql driver in the common/lib directory. > I > have also tried placing it in the web-inf/lib directory with no better > results. Help please! > > > > package org.jugaccino.servlet; > > > > import java.io.IOException; > > import java.io.PrintWriter; > > import java.sql.*; > > import javax.servlet.ServletConfig; > > import javax.servlet.ServletException; > > import javax.servlet.http.*; > > import org.apache.commons.dbcp.*; > > import org.apache.commons.pool.impl.GenericObjectPool; > > > > public class DriverTestMaual extends HttpServlet > > { > > > > public DriverTestMaual() > > { > > } > > > > public void init(ServletConfig config) > > throws ServletException > > { > > super.init(config); > > } > > > > public void destroy() > > { > > } > > > > protected void processRequest(HttpServletRequest request, > HttpServletResponse response) > > throws ServletException, IOException > > { > > response.setContentType("text/html"); > > PrintWriter out = response.getWriter(); > > System.setProperty("jdbc.drivers","com.mysql.jdbc.Driver"); > > try > > { > > org.apache.commons.pool.ObjectPool connectionPool = new > GenericObjectPool(null); > > org.apache.commons.dbcp.ConnectionFactory connectionFactory = new > DriverManagerConnectionFactory("jdbc:mysql://localhost/ > jugaccino?user=xx > x&password=xxx;", null); > > PoolableConnectionFactory poolableConnectionFactory = new > PoolableConnectionFactory(connectionFactory, connectionPool, null, > null, > false, true); > > PoolingDriver driver = new PoolingDriver(); > > driver.registerPool("jugaccino", connectionPool); > > } > > catch(Exception ex) > > { > > ex.printStackTrace(); > > out.println(ex); > > return; > > } > > Connection conn = null; > > Statement stmt = null; > > ResultSet rset = null; > > try > > { > > out.println("Creating connection."); > > conn = > DriverManager.getConnection("jdbc:apache:commons:dbcp:jugaccino"); > > out.println("Creating statement."); > > stmt = conn.createStatement(); > > out.println("Executing statement."); > > rset = stmt.executeQuery("select downloads from > downloadcount"); > > out.println("Results:"); > > if(rset.next()) > > out.println(rset.getInt("downloads")); > > } > > catch(SQLException e) > > { > > e.printStackTrace(); > > out.println(e.getMessage()); > > } > > finally > > { > > try > > { > > rset.close(); > > } > > catch(Exception e) { } > > try > > { > > stmt.close(); > > } > > catch(Exception e) { } > > try > > { > > conn.close(); > > } > > catch(Exception e) { } > > } > > out.close(); > > } > > > > protected void doGet(HttpServletRequest request, > HttpServletResponse > response) > > throws ServletException, IOException > > { > > processRequest(request, response); > > } > > > > protected void doPost(HttpServletRequest request, > HttpServletResponse response) > > throws ServletException, IOException > > { > > processRequest(request, response); > > } > > > > public String getServletInfo() > > { > > return "Short description"; > > } > > } >