I have a method call I think probably does what you want
public static Connection getPooledConection(String JNDIName) {
Connection con = null;
DataSource ds = null;
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("jdbc/"+JNDIName);
con = ds.getConnection();
}
catch(Exception e){
System.out.println(new java.util.Date()+" Blah Blah Blah\n"+
"Conection was forced closed!\n"+
"JNDIName : "+JNDIName+"\n"+e+"\n"+e.getMessage()+"\n\n"+
e.printStackTrace() );
try { con.close(); } catch(Exception d) { }
} // Close exception catch
return con;
} // Close method
Scott Purcell wrote:
Hello,
I want to say thanks for the links yesterday in regards to my pooling problem.
After reading the docs, I have a better handle on how this will work.
I am ready to test, and I was able to get the following to work within a JSP
page.
But I would really like to create a Singleton class that could hand out connections based upon
something like: singleton.getHandle("jndiname"); So in my business object I can hand in a
"name" and let the busines object get the connection, etc.
Does that make sense. Only problem is, I cannot figure out how to transfer the
JSP snippet below, to physical java code.
Anyone know?
Thanks,
Scott
####### JSP that works correctly ... would like to do this in a class #######
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="jdbc/TestDB">
select id, foo, bar from testdata
</sql:query>
<html>
<head>
<title>DB Test</title>
</head>
<body>
<h2>Results</h2>
<c:forEach var="row" items="${rs.rows}">
Foo ${row.foo}<br/>
Bar ${row.bar}<br/>
</c:forEach>
</body>
</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Brian Cook
Digital Services Analyst
Print Time Inc.
[EMAIL PROTECTED]
913.345.8900
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]