• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web Application

 
vishal sodani
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing a web application,using JSP's,servlets and html.Now I want to test it on JSwdk.It is a database driven application.My problem is that I want to open a connection to the database once,and then use that connection object throughout my application.How can I do it in JSWDK?Please help!
 
Vlad Patryshev
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not clue what JSWDK is, but in JSP you can have application bean, and your singleton connection can be its attribute. (Or property, whatever.)
 
vishal sodani
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After opening a connection with application bean,can I use the connection object throughtout in various servlets and jsp's?
 
DAYANAND BURAMSHETTY
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think U can't because If U open connection this is useful for only one operation
after completion this operation U have to close this connection.For another
operation U have to open connection.
If I'm wrong.... Correct me
 
Michael Arnett
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I believe one connection can be used for multiple operations, unless the specific db driver you are using does not allow this. I do know that each statement can have only one active resultset. Maybe you were thinking of that. Also, yes once an application bean's connection is initialized, it can used by any jsp / servlet. The code would look something like:
<jsp:useBean id="ConnectBeanId" scope="application" class="ConnectBean" />
Where ConnectBean is a class that looks like:
public class ConnectBean
{
Connection myConnection = null;
public ConnectBean
{
Class.forName(oracle.jdbc.driver.OracleDriver);
Connection myConnection = DriverManager.getConnection(jdbc: oracle:thin:scott/tiger@mysite.com:1521:myDb);
}
public boolean isClosed()
{
return myConnection.isClosed();
}
.
.
.
.
.
}

Later on another jsp page could have something like:
<jsp:useBean id="ConnectBeanId" scope="application" class="ConnectBean" />
<% if (ConnectBeanId.isClosed == true)
System.out.println ("You keep a-knocking but you can't come in!");
%>
In this scenario, if an instance of ConnectBean has already been instantiated, then the useBean directive will utilize that current instance rather than construct a new one (and all of its current members/properties will remain set to the current values/states)...otherwise it creates a new bean who's lifetime is set to application.
Hopefully this is helpful and/or legible and/or correct .
-MLA


[This message has been edited by Michael Arnett (edited August 08, 2001).]
[This message has been edited by Michael Arnett (edited August 08, 2001).]
 
Vlad Patryshev
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are different attitudes to connections, of course, but I would prefer to keep my connection open in my application bean and use it for all the database operations.
The other way is to delegate this responsibility to an application server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic