You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason <ja...@asiacontent.com> on 2001/04/17 10:22:06 UTC

Re: How to make DbConnectionBroker from javaexchange.com to work with Mysql?

Hi Jeff,

    this is the example from DbConnectionBroker.  I follow your advise to modify
this program but get "javaNullPointer exception" when calling "conn =
myBroker.getConnection()".  By the way, I am using the same JDBC driver
"org.gjt.mm.mysql.Driver".
    I've used String dbServer="jdbc:mysql://192.168.36.1:3306/adv" or String
dbServer="jdbc:mysql://192.168.36.1:3306 or String
dbServer="jdbc:mysql://192.168.36.1/adv" or String
dbServer="jdbc:mysql://192.168.36.1" without any success.
"
    Any idea?

Thanx

Jason

---------------------------My code---------------------------
import com.javaexchange.dbConnectionBroker.*;

public class Example1 extends HttpServlet
{
    DbConnectionBroker myBroker;
    String dbDriver="org.gjt.mm.mysql.Driver";
    String dbServer="jdbc:mysql://192.168.36.1:3306/adv";
    String dbLogin="correct_username";
    String dbPassword="correct_password";
    int minConns=2;
    int maxConns=20;
    String logFile="logfile";
    double recycleTime=5.0;

    public void init (ServletConfig config) throws ServletException {
        super.init(config);
        try
        {
          myBroker = new
DbConnectionBroker(dbDriver,dbServer,dbLogin,dbPassword,minConns,maxConns,logFile,recycleTime);

        }
        catch (IOException e5)
        {
        }
    }

    public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
    {
        PrintStream out = new PrintStream (response.getOutputStream());
        Connection conn;
        Statement stmt = null;
        int thisConnection;
        response.setContentType ("text/html");

        try {
            // Get a DB connection from the Broker
            conn = myBroker.getConnection();
             .
             .
        }
        catch (...)
        { }
    }
}
---------------------------End of My code---------------------------









Jeff Kilbride wrote:

> There's very good documentation and examples at javaexchange.com, but here's
> a quickie overview:
>
> -------------------------------
> import com.javaexchange.dbConnectionBroker.*;
>
> DbConnectionBroker _broker;
> String dbDriver="org.gjt.mm.mysql.Driver";
> String dbServer="jdbc:mysql://localhost:3306";
> String dbLogin="your_login";
> String dbPassword="your_password";
> int minConns=2;
> int maxConns=20;
> String logFile="path/to/your/log/file";
> double recycleTime=5.0;
>
> _broker = new DbConnectionBroker(dbDriver,
>                                                          dbServer,
>                                                          dbLogin,
>                                                          dbPassword,
>                                                          minConns,
>                                                          maxConns,
>                                                          logFile,
>                                                          recycleTime);
>
> Connection conn = _broker.getConnection();
>
> // Normal use of connection here....
>
> _broker.freeConnection(conn);
> -------------------------------
>
> I'm assuming you're using the mm.mysql driver and connecting to localhost.
> If not, you need to change the dbDriver and dbServer strings. At
> javaexchange.com, there are examples for implementing a Singleton pattern
> and using inheritance to make it easier to use the connection broker in your
> code. I suggest you go through the docs. You can even view them online:
>
> http://www.javaexchange.com/
>
> Thanks,
> --jeff
>
> ----- Original Message -----
> From: "Jason" <ja...@asiacontent.com>
> To: <to...@jakarta.apache.org>
> Sent: Monday, April 16, 2001 7:51 PM
> Subject: How to make DbConnectionBroker from javaexchange.com to work with
> Mysql?
>
> > Hi everyone,
> >
> >     anyone knows how to use DbConnectionBroker from javaexchange.com to
> > connect to MYSQL instead of to Oracle?  My application is using Mysql
> > and it runs fine.  Now I want to use connection pooling to improve the
> > performance before deployment.  However, I cannot make
> > DbConnectionBroker and Mysql work together.  Any idea?
> >
> > Thanx!
> >
> > Jason
> >


Re: How to make DbConnectionBroker from javaexchange.com to work with Mysql?

Posted by Jeff Kilbride <je...@kilbride.com>.
Hi Jason,

It looks like you're doing everything right. What does the logfile say? Here
is an example of my logfile with two open connections:

---------------------------
Starting DbConnectionBroker Version 1.0.11:
dbDriver = org.gjt.mm.mysql.Driver
dbServer = jdbc:mysql://localhost:3306/affiliates
dbLogin = myLogin
log file = /var/log/mysql/broker.log
minconnections = 2
maxconnections = 20
Total refresh interval = 5.0 days
-----------------------------------------
Tue Apr 17 00:15:56 CDT 2001  Opening connection 0
org.gjt.mm.mysql.jdbc2.Connection@383b162a:
Tue Apr 17 00:15:56 CDT 2001  Opening connection 1
org.gjt.mm.mysql.jdbc2.Connection@6e729629:
---------------------------

Thanks,
--jeff

----- Original Message -----
From: "Jason" <ja...@asiacontent.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, April 17, 2001 1:22 AM
Subject: Re: How to make DbConnectionBroker from javaexchange.com to work
with Mysql?


> Hi Jeff,
>
>     this is the example from DbConnectionBroker.  I follow your advise to
modify
> this program but get "javaNullPointer exception" when calling "conn =
> myBroker.getConnection()".  By the way, I am using the same JDBC driver
> "org.gjt.mm.mysql.Driver".
>     I've used String dbServer="jdbc:mysql://192.168.36.1:3306/adv" or
String
> dbServer="jdbc:mysql://192.168.36.1:3306 or String
> dbServer="jdbc:mysql://192.168.36.1/adv" or String
> dbServer="jdbc:mysql://192.168.36.1" without any success.
> "
>     Any idea?
>
> Thanx
>
> Jason
>
> ---------------------------My code---------------------------
> import com.javaexchange.dbConnectionBroker.*;
>
> public class Example1 extends HttpServlet
> {
>     DbConnectionBroker myBroker;
>     String dbDriver="org.gjt.mm.mysql.Driver";
>     String dbServer="jdbc:mysql://192.168.36.1:3306/adv";
>     String dbLogin="correct_username";
>     String dbPassword="correct_password";
>     int minConns=2;
>     int maxConns=20;
>     String logFile="logfile";
>     double recycleTime=5.0;
>
>     public void init (ServletConfig config) throws ServletException {
>         super.init(config);
>         try
>         {
>           myBroker = new
>
DbConnectionBroker(dbDriver,dbServer,dbLogin,dbPassword,minConns,maxConns,lo
gFile,recycleTime);
>
>         }
>         catch (IOException e5)
>         {
>         }
>     }
>
>     public void doGet (HttpServletRequest request, HttpServletResponse
response)
> throws ServletException, IOException
>     {
>         PrintStream out = new PrintStream (response.getOutputStream());
>         Connection conn;
>         Statement stmt = null;
>         int thisConnection;
>         response.setContentType ("text/html");
>
>         try {
>             // Get a DB connection from the Broker
>             conn = myBroker.getConnection();
>              .
>              .
>         }
>         catch (...)
>         { }
>     }
> }
> ---------------------------End of My code---------------------------
>
>
>
>
>
>
>
>
>
> Jeff Kilbride wrote:
>
> > There's very good documentation and examples at javaexchange.com, but
here's
> > a quickie overview:
> >
> > -------------------------------
> > import com.javaexchange.dbConnectionBroker.*;
> >
> > DbConnectionBroker _broker;
> > String dbDriver="org.gjt.mm.mysql.Driver";
> > String dbServer="jdbc:mysql://localhost:3306";
> > String dbLogin="your_login";
> > String dbPassword="your_password";
> > int minConns=2;
> > int maxConns=20;
> > String logFile="path/to/your/log/file";
> > double recycleTime=5.0;
> >
> > _broker = new DbConnectionBroker(dbDriver,
> >                                                          dbServer,
> >                                                          dbLogin,
> >                                                          dbPassword,
> >                                                          minConns,
> >                                                          maxConns,
> >                                                          logFile,
> >                                                          recycleTime);
> >
> > Connection conn = _broker.getConnection();
> >
> > // Normal use of connection here....
> >
> > _broker.freeConnection(conn);
> > -------------------------------
> >
> > I'm assuming you're using the mm.mysql driver and connecting to
localhost.
> > If not, you need to change the dbDriver and dbServer strings. At
> > javaexchange.com, there are examples for implementing a Singleton
pattern
> > and using inheritance to make it easier to use the connection broker in
your
> > code. I suggest you go through the docs. You can even view them online:
> >
> > http://www.javaexchange.com/
> >
> > Thanks,
> > --jeff
> >
> > ----- Original Message -----
> > From: "Jason" <ja...@asiacontent.com>
> > To: <to...@jakarta.apache.org>
> > Sent: Monday, April 16, 2001 7:51 PM
> > Subject: How to make DbConnectionBroker from javaexchange.com to work
with
> > Mysql?
> >
> > > Hi everyone,
> > >
> > >     anyone knows how to use DbConnectionBroker from javaexchange.com
to
> > > connect to MYSQL instead of to Oracle?  My application is using Mysql
> > > and it runs fine.  Now I want to use connection pooling to improve the
> > > performance before deployment.  However, I cannot make
> > > DbConnectionBroker and Mysql work together.  Any idea?
> > >
> > > Thanx!
> > >
> > > Jason
> > >
>


Re: How to make DbConnectionBroker from javaexchange.com to work with Mysql?

Posted by Jason <ja...@asiacontent.com>.
Hi Jeff,

    it works now!  It's the path of the logfile causing the problem.

Thanx

Jason

Jason wrote:

> Hi Jeff,
>
>     this is the example from DbConnectionBroker.  I follow your advise to modify
> this program but get "javaNullPointer exception" when calling "conn =
> myBroker.getConnection()".  By the way, I am using the same JDBC driver
> "org.gjt.mm.mysql.Driver".
>     I've used String dbServer="jdbc:mysql://192.168.36.1:3306/adv" or String
> dbServer="jdbc:mysql://192.168.36.1:3306 or String
> dbServer="jdbc:mysql://192.168.36.1/adv" or String
> dbServer="jdbc:mysql://192.168.36.1" without any success.
> "
>     Any idea?
>
> Thanx
>
> Jason
>
> ---------------------------My code---------------------------
> import com.javaexchange.dbConnectionBroker.*;
>
> public class Example1 extends HttpServlet
> {
>     DbConnectionBroker myBroker;
>     String dbDriver="org.gjt.mm.mysql.Driver";
>     String dbServer="jdbc:mysql://192.168.36.1:3306/adv";
>     String dbLogin="correct_username";
>     String dbPassword="correct_password";
>     int minConns=2;
>     int maxConns=20;
>     String logFile="logfile";
>     double recycleTime=5.0;
>
>     public void init (ServletConfig config) throws ServletException {
>         super.init(config);
>         try
>         {
>           myBroker = new
> DbConnectionBroker(dbDriver,dbServer,dbLogin,dbPassword,minConns,maxConns,logFile,recycleTime);
>
>         }
>         catch (IOException e5)
>         {
>         }
>     }
>
>     public void doGet (HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException
>     {
>         PrintStream out = new PrintStream (response.getOutputStream());
>         Connection conn;
>         Statement stmt = null;
>         int thisConnection;
>         response.setContentType ("text/html");
>
>         try {
>             // Get a DB connection from the Broker
>             conn = myBroker.getConnection();
>              .
>              .
>         }
>         catch (...)
>         { }
>     }
> }
> ---------------------------End of My code---------------------------
>
> Jeff Kilbride wrote:
>
> > There's very good documentation and examples at javaexchange.com, but here's
> > a quickie overview:
> >
> > -------------------------------
> > import com.javaexchange.dbConnectionBroker.*;
> >
> > DbConnectionBroker _broker;
> > String dbDriver="org.gjt.mm.mysql.Driver";
> > String dbServer="jdbc:mysql://localhost:3306";
> > String dbLogin="your_login";
> > String dbPassword="your_password";
> > int minConns=2;
> > int maxConns=20;
> > String logFile="path/to/your/log/file";
> > double recycleTime=5.0;
> >
> > _broker = new DbConnectionBroker(dbDriver,
> >                                                          dbServer,
> >                                                          dbLogin,
> >                                                          dbPassword,
> >                                                          minConns,
> >                                                          maxConns,
> >                                                          logFile,
> >                                                          recycleTime);
> >
> > Connection conn = _broker.getConnection();
> >
> > // Normal use of connection here....
> >
> > _broker.freeConnection(conn);
> > -------------------------------
> >
> > I'm assuming you're using the mm.mysql driver and connecting to localhost.
> > If not, you need to change the dbDriver and dbServer strings. At
> > javaexchange.com, there are examples for implementing a Singleton pattern
> > and using inheritance to make it easier to use the connection broker in your
> > code. I suggest you go through the docs. You can even view them online:
> >
> > http://www.javaexchange.com/
> >
> > Thanks,
> > --jeff
> >
> > ----- Original Message -----
> > From: "Jason" <ja...@asiacontent.com>
> > To: <to...@jakarta.apache.org>
> > Sent: Monday, April 16, 2001 7:51 PM
> > Subject: How to make DbConnectionBroker from javaexchange.com to work with
> > Mysql?
> >
> > > Hi everyone,
> > >
> > >     anyone knows how to use DbConnectionBroker from javaexchange.com to
> > > connect to MYSQL instead of to Oracle?  My application is using Mysql
> > > and it runs fine.  Now I want to use connection pooling to improve the
> > > performance before deployment.  However, I cannot make
> > > DbConnectionBroker and Mysql work together.  Any idea?
> > >
> > > Thanx!
> > >
> > > Jason
> > >