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";
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
