On Tue, 2004-04-13 at 15:38, Parsons Technical Services wrote:
> Paul,
> 
> Everything looks okay until here:
> >
> >     DataSource ds = null;
> >     try {
> >         Context ctx = new InitialContext();
> >         ds =
> > (DataSource)ctx.lookup("java:comp/env/jdbc/PhoenixDB");
> >         if (ds == null)
> >             throw new Exception("DS was null");
> >         ds.getConnection("phoenix", "ashes").close();
> >     } catch (Exception e) {
> >         out.println("JNDI lookup failed");
> >         e.printStackTrace(out);
> >         MysqlConnectionPoolDataSource dsi = new
> > com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource();
> >         dsi.setURL("jdbc:mysql://drusilla.central/phoenix");
> >         ds = dsi;
> >     }
> >
> >     Connection con =  ds.getConnection("phoenix", "ashes");
> >     out.println("Created connection to database.");
> 
> This line is trying to close the connection you just tried to get.
> >         ds.getConnection("phoenix", "ashes").close();
> 

This is deliberate.  This is to test that the DataSource I get actually
works.

> This needs to be inside the catch block.
> >     Connection con =  ds.getConnection("phoenix", "ashes");
> 

Em no.. If the JNDI test fails then the catch block gets the Mysql
datasource manually.

The code after the try/catch executes using the DataSource set by
whichever method worked.  It should work no matter where the DataSource
came from.


> 
> Try this code:
> 
>      DataSource ds = null;
>      Connection con = null;
>      try {
>          Context ctx = new InitialContext();
>          ds = (DataSource)ctx.lookup("java:comp/env/jdbc/PhoenixDB");
>          if (ds == null)
>              throw new Exception("DS was null");
>         con = ds.getConnection();
>      } catch (Exception e) {
>          out.println("JNDI lookup failed");
>          e.printStackTrace(out);
>          MysqlConnectionPoolDataSource dsi = new
>  com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource();
>          dsi.setURL("jdbc:mysql://drusilla.central/phoenix");
>          ds = dsi;
>      con =  ds.getConnection("phoenix", "ashes");
>      }
> 
>      out.println("Created connection to database.");
> 
> 
> See if it give you a connection. Also note that you were not getting a DS
> was null exception, which is what you should have got if the ctx.lookup
> failed.
> 
> 

Yes I know this.  This is why I said in my previous emails that I didn't think the 
JNDI binding was failing.  I suspect that it is more to do with the parameters being 
passed incorrectly from the server.xml..



-- 
Paul Richards <[EMAIL PROTECTED]>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to