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 needs to be inside the catch block.
> Connection con = ds.getConnection("phoenix", "ashes");
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.
Doug
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]