Caching of Database Access Objects possible?

I am working on a web application. I am using Struts for the presentation layer. Also I am using DAO pattern for Database layer.
My doubt is about creating instance of DAO's. I am created a DAO Factory which can create instances of DAO's. Whether I can go for caching of DAO or Do I have to create a new DAO for everytime? Would caching done as shown in the code below create Concurrency issues? or please suggest the right way of going about it.
My Struts Action code is as follows:
public class WelcomeAction extends Action { static Category log = Category.getInstance(WelcomeAction.class.getName()); public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try{ UserDAO userDAO = (UserDAO)DAOFactory.getInstance("com.share.dao.UserDAO"); ResultObj obj = (ResultObj)userDAO.getUserList(); List userList = (ArrayList)obj.getResults(); request.setAttribute("userList", userList); }catch(Exception e){ e.printStackTrace(); return mapping.findForward("errorPage"); } return mapping.findForward("success"); }
UserDAO code is as follows:
public abstract class UserDAO extends BaseDAO { public Object getUserList() throws DBException{ Connection conn = null; PreparedStatement stmt = null; Object obj = null; try{ conn = DBConnectionManager.getConnection(); stmt = conn.prepareStatement("Select * from USER_INFO where USER_ID like ?"); stmt.setMaxRows(3); stmt.setString(1, "%"); stmt.executeQuery(); obj = processGetUserList(stmt); }catch(SQLException e){ throw new DBException(e.getMessage()); }finally{ DBConnectionManager.close(stmt); DBConnectionManager.closeConnection(conn); } return obj; }
And the DAO Factory is as follows:
package com.share.dao; import java.util.HashMap; public class DAOFactory { private static HashMap hash = new HashMap();     public DAOFactory()     {     }     public static BaseDAO getInstance(String daoName)     {         BaseDAO dao = null;         try         {             dao = (BaseDAO)hash.get(daoName);             if(dao == null)                 dao = createNewInstance(daoName);         }         catch(Exception ex)         {             ex.printStackTrace();         }         return dao;     }     private static synchronized BaseDAO createNewInstance(String daoName)     {         BaseDAO dao = null;         try         {             dao = (BaseDAO)hash.get(daoName);             if(dao != null)                 return dao;             Class daoClass = Class.forName(daoName + "Impl");             dao = (BaseDAO)daoClass.newInstance();             hash.put(daoName, dao);         }         catch(Exception ex)         {             ex.printStackTrace();         }         return dao;     } }

palak123i wrote:
I am working on a web application. I am using Struts for the presentation layer. Also I am using DAO pattern for Database layer.
My doubt is about creating instance of DAO's. I am created a DAO Factory which can create instances of DAO's. Why do you do that? Why not just create the DAOs at startup and give the Actions a reference to the DAOs they need? Less complicated that way.
Or just have the DAOFactory hide the caching from you. Have it create all the DAOs you need on instantiation, put them in a Map, and dole them out on lookup.
Whether I can go for caching of DAO or Do I have to create a new DAO for everytime? Would caching done as shown in the code below create Concurrency issues? or please suggest the right way of going about it.All your code needs to be thread safe, of course. As long as your DAOs don't have any any private data members you should be all right there.
I would pass the Connection to the DAO, because it should be created and cleaned up by another object that knows about transactions and units of work. The DAO can't be expected to know all the business contexts in which it is used.
I never liked Struts. Your Action class shows why - this code is useless without the web layer. The only way to reuse this code is to hack it away from Struts. A separate service layer that didn't have any knowledge of the web tier would be a good step towards that goal.
%

Similar Messages

  • Database access patterns

    I've been wondering for a while what techniques people use to access databases. I'm not talking about the JDBC API but how are applications designed. One obvious objective is to consolidate all database access into one package and not have SQL strewn throughout the app. This obviously helps for abstraction purposes, you could easily change the backend, but also makes for easy updates if you make a schema change. I've read about the Database Access Object pattern and like the idea of seperating database access details from the rest of the application. My question is one of implementation. Say you use something like the DAO pattern. Now you have one database access class for each business object and typically (not always) there is a 1:1 mapping of business objects to database tables. How do you actually implement the DAO class? Do you write a single method for each type of query you may perform? For example, say I have a simple schema where table A references table B and table B references tables C. I could query for Object C (from table C) in a number of ways such as:
    select * from tableC, tableB where tableC.column2=tableB.column1 and tableB.column3=1234;
    or
    select * from tableC, tableB, tableA where tableC.column2=tableB.column1 and tableB.column2=tableA.column1;
    and so on . . .
    I'm wondering if people use some kind of abstraction to dynamically genereate the sql query on the fly or do you simple have seperate method calls for each query and just drop in the values:
    ObjectC getCfromB(int tableBcolumn3Value){
    String sql="select * from tableC where tableC.column2=tableB.column1 and tableB.column3="+tableBcolumn3Value;
    //do your JDBC stuff and return ObjectC
    Is there a way of having the database access classes understand the schema of your DB so if you supply a column from tableB and ask for objectC it knows what to do?
    It seems labor intesive to have to write a method for each type of query,insert, update,delete you might do. How do people handle this? Are there any other standard/accepted methods of separating database details from the rest of the app, other than the DAO pattern?
    thanks

    I'm trying to dive into an object/relational mapping layer. I don't want to have to write and maintain DTOs for every application.
    I looked into OJB from Jakarta first. I liked the cache it had as part of the Jakarta family. It worked fine, but I was uncomfortable with the level of documentation.
    I'm diving into Hibernate now. It seems to have more traction, and there's more documentation. I like the XDoclet/Ant tie-in. Gavin King is working with JBoss now, so Hibernate will be wired into JBoss in the future.
    I hope I can make Hibernate a standard part of my repertoire.
    If you'd rather not go that way, Martin Fowler's "Patterns Of Enterprise Application Architecture" has several approaches to the problem of data mapping layers.- MOD

  • Object services - manual implementation of database access layer

    Hello,
    this is my first time with object services. I read a lot but can't find the information which I really need to implement my requirements.
    I have build a persistent class, clicked to "persistence", mapped my persistent attributes. I want to use a table-like attribute in my class, which contains references to another class. I added this attribute manually to the attribute list in the class builder. Consequently, GET and SET methods were generated automatically. Then I changed the generator settings by activating "manual implementation of database access layer".
    So, my first notice is - If I choose manual implementation a call of create_persistent-method will not work. Nothing will be inserted into the mapped data base table.
    Can anybody give me a example which shows how I can implement the database access layer manually? What do I have to do to write object attributes into data base table?
    Which methods do I have to enhance?
    Thanks a lot for any help in advance!
    Anne

    Thanks for your answer, but I would not be sure if you really got my problem.
    I really really read much stuff (including SAP help, sappress "object services in ABAP" by Assig, Fobbe, Niemitz, sappress "abap objects" by keller), I googled a lot. But I couldn't find detailed information about this manual implementation of database access which you can activate in persistence settings.
    This is the only extract out of SAP Help regarding this topic:
    "If you prefer to carry out a manual implementation of the database access layer, select  to change the generator settings and select the field of the same name. In this case you can implement your own database read routines, through which you can redefine the generated SET and GET methods for access to the database. This is particularly recommended if you want to improve performance by providing these routines with their own buffer mechanism. "
    And some information about so calles Structure mapping which means the same idea in my opinion
    "Structure Mapping
    In this case, you map ABAP Dictionary structures, rather than database tables or database views to persistent objects. The application developer must therefore program the type of persistent data storage in the appropriate methods of the class actor.
    You will need to map a structure (or structures) if you want a persistent object to contain table-like attributes. Database tables can only have flat structures, which prevents your mapping the object to a table in this case. You must still use structure mapping, even if you want to store the data in a different form u2013 such as in a file on the application server."
    I used the debugger to get the idea of the SAVE method. But I couldn't find the difference between manual and automatic implementation in the code.
    I tried to use implicit enhancement, but was not successful. Right now I am trying to redefine the SAVE method of the interface IF_OS_CA_SERVICE. But I can't believe that I have to implement the whole attribute-table-mapping on my own now. That can't be the idea of object service and their manual implementation. In my opinion it must be possible to use predefined algorithm to map business key etc. to corresponding table fields and to implement own ideas just for those table-like attributes..
    Or am I totally wrong with this thoughts?
    Thanks in advance!!
    Anne

  • Database access code in objects constructor, or in data access object

    Given an object that is stored in a database, is it better to have the database access code in a constructor method, or a data access layer object? E.g. I have a Person class
    public class Person{
    int Id;
    String name;
    int age;
    }When I want to read a person's details from the database, I could use a constructor something like this:
    public Person(int id){
    Connection con = getDatabaseConnection();
    ResultSet rs = con.createStatement().executeQuery("Select name, age from person where person_id = " + id);
    rs.next();
    this.name = rs.getString(1);
    this.age=rs.getInt(2);
    }Or I could use a method in a data access object :
    public Person getPerson(int id){
    Person p = new Person();
    Connection con = getDatabaseConnection();
    ResultSet rs = con.createStatement().executeQuery("Select name, age from person where person_id = " + id);
    rs.next();
    p.setName(rs.getString(1));
    p.setAge(rs.getInt(2));
    return p;
    }It seems to me that the constructor approach has two advantages
    (1) the SQL code is kept in the relevant class (so if I want to add a field to Person, I only have to make changes to the Person class)
    (2) I don't have to have a setter method for each field
    Is one or other of these ways generally recognized as 'best practise'?

    malcolmmc wrote:
    But then, on the other hand, everytime a Person gains a new field that's two places you have to change it. if the persistence interface is written in terms of the object and uses ORM, I don't have to touch the implementation. all i have to do is update the object, the database, and the mapping - just like you and your home brew ORM.
    besides, so what? i'd fear the resource leak, bad layering, more difficult testing more.
    Actually lately I've used annotations to label setters with database field names and run a simple home brew ORM to convert rows into objects even when not using a more complex persistence manager.home brew ORM? why is that necessary when you can choose from hibernate, ibatis, jdo, jpa, etc.? that's just nuts.
    %

  • Error : Access not possible using "null" objects reference

    Hello.
    i am working with a zbapi.
    i called a external email program in this bapi,everything is working fine over here.
    In webdynpro java they mapped my bapi and starting working from there.
    every functionality is working fine but regarding this email stuff it is showing an error as access not possible using null objects reference.
    where could be the possible error.
    is it in webdynpro or in abap side.

    Raghu,
    You are right. When it comes from the WD Java, may be you are not passing any value at all. You can trace it by these ways.
    1. Check it using SE37, make sure everyhting is fine.
    2. Print all the values that you are passing to the RFC in the execute RFC method().
    3. using ST05 transaction in R/3, enable RFC and SQL trace, check what is passing in between web dynpro and R/3.
    Moreover paste your error message here.
    Thanks,
    Raj.

  • Database access in a MVC architecture

    Hi!
    I'm a bit confused with regards to where the database access code should be put in a MVC architecture. From reading various articles and posts on this forum, there seem to be a lot of different opinions.
    Some seem to put the database access code in the controller servlet(or JSP), while some seem to use helper classes from the JavaBeans, while a few people even seem to access the database directly from the JavaBean.
    My questions is: What is the best place to put the database stuff in a MVC architecture? An explanation as to why a particular solution is the best would be great..
    Thanks!
    regards,
    Vidar

    Let's say I have a class called Department that contains methods like getName(), getId(), setName(), etc... The Department class is my business object. To save and load Departments from a database, I have a class called DepartmentManager. The DepartmentManager saves and loads the departments to the database, and has methods like saveDepartment(), saveDepartments(), loadDepartment(), getDepartments(), etc... In some cases, my manager classes also caches the results so they don't have to load from the database each time. Often times, the manager class is a singleton. My Department class has no idea how it is persisted, or that it is part of a cache. It just knows about itself. The DepartmentManager is resonsible for managing all the persistance and lookup functionality for Departments.
    Therefore, if I have a JSP page that needs to display Departments, my code might look like:
    DepartmentManager dm = DepartmentManager.getManager();
    ArrayList listDepartments = dm.getDepartmentList();
    for (int i = 0; listDepartments != null && i < listDepartments.size(); i++) {
         Department dept = (Department)listDepartments.get(i);
         out.println("<option value=\"" + dept.getId() + "\">" + dept.getName());
    }If I had a specific Department I needed, I would get it as follows:
    DepartmentManager dm = DepartmentManager.getManager();
    Department dept = dm.getDepartment(nId);

  • Database access from session bean

    Hello,
    I have a stateless session bean which performs some complex
    calculations, and also does some database access.
    For the database access the bean class has a datasource as
    follows:
    public class TestBean implements SessionBean {
    private DataSource ds_;
    public void ejbCreate() {
         getDataSources();
    private void getDataSources() {
         try {
         Context ictx = new InitialContext();
         ds_ = (DataSource)ictx.lookup("java:comp/env/jdbc/TestDB");
         } catch (Exception e) {
         e.printStackTrace();
         throw new EJBException(e);
    Now this class has a method (which is also in the remote interface)
    calculateSomething(). This method constructs a number of other
    objects that do the actual calculation, and one of these objects
    does the actual database access. How would another object be able to
    use the datasource that was constructed in the bean class?
    I could pass the datasource reference to that object, but that would
    break my encapsulation. This is because that object does not get
    created directly by the bean object, but rather the way the objects
    interact is something like A -> B -> C, where A is the TestBean, and
    C is the object that does the DB access. If I passed the datasource,
    I would need to make B aware of the datasource, which doesn't
    seem good design, because B doesn't do any database access.
    Alternatively I could do the lookup in class C, but that would
    degrade the performance, as an object C gets created and destroyed
    every time the calculateSomething() method is called.
    A third option I have thought of, is to add a public method to the
    bean that returns a connection. Whenever another object gets
    created, a reference to the bean object will be passed along. Then,
    if another object needs to do database access, it will call back
    the bean to get a connection. This seems just as bad (if not worse)
    than the first option.
    Does anyone have an elegant solution for this situation? What is
    the best practice of handling datasources when a bean class doesn't
    do the database access itself? In all the examples I've seen so far,
    all the functionality was in the session bean class, but again that
    doesn't seem good OO design, and would result in a single huge class.
    regards,
    Kostas

    Thanks again to both for the replies. Here are my responses:
    Yi Lin: Yes, I know that an entity bean would solve this problem, however it has been decided not to use entity beans so this is not my call (I think the reason entity beans are not allowed in this project is that they are considered risky: there are other applications that access the same database, so if the container caches entity bean data as you describe, then the users might get inconsistent results).
    Gerard: Actually object B is the one that has the business logic and C is a peer object that only does database access and no calculaitons. For example B can be Customer, and C CustomerDB. This is why object B does not have any knowledge of datasources or connections. So my design does not appear to be that bad!
    As far as the factory you propose is concerned, I cannot understand how this would solve my problem. In order to solve this situation the factory would need to be persistent, i.e. get created by the ejbCreate() method, and destroyed whenever the container decides to destroy the bean. There would be no point in object C creating the factory, as I would have the overhead of doing the JNDI lookup every time I create a C.
    So the question remains the same: how would I pass a reference to the factory from A to C without making B aware of it?

  • Database access... what is the best approach

    in a nutshell...
    i have an applet that needs to access three data bases... currently i have it written and completed and working but the lag time on the database access is really slow so i am questioning my approach to the problem...
    as a buisness rule we wanted to create classes to access the data through accessor mehtods from applications and appletts therfore standardizing our field name conventions, our methods and so on and so on...
    so when the applett runs it creates an object for each class that access the database... when the user enters a valid "parcel number" the parcel is passed to the first class and the record is retrieved for database "A" and then it is passed to the next class and the supporting records are retrieved for data base "B" and it repeats the same concept for database "C".. so now i have the applet running and accessing the data through accessor methods through those objects...
    each class makes the conection to the data base.. issues the sql, stores the results and closes the connection
    i'll admit i am somewhat new to the java envirnoment so any help on concepts and approach would be most appreciated and useful
    does this approach seem reasonable or am i letting my 15 years of procedural thinking get the best of me...
    what would be the most effiecent way of doing this?
    how much of a performance gain would i see if i threaded each one out on it's own thread and how would i do that?
    the end product is going to be a county taxation system using browser technology as an inquiry system for public and general use and an application environment for inhouse data entry and use
    creating seperate classes for each of the data basses seems ideal for what we want to do but maybe it is counterproductive considering the lag times.
    i am using JDBC against an HP3000 image DataBase

    With the information given that is the only possible approach.
    You could provide a middle layer which would then handle some of the interactions for you. For instance by keeping a connection pool.
    Additionally if your databases are not actually distributed (and the same vendor) then you could do most of the work in a stored procedure. You could also do this if some of the data is relatively static and by using a server side replication process.

  • Database access through Beans

    My question is about high level design. I've written some JSP pages and some very simple JavaBeans that work on Tomcat.
    Now I'm trying to design a Database access layer
    I want to have a connection pool class and some other business logic classes communicating with each other.
    How can I start a bean and keep it running and how do I access its methods from other beans?
    Is this even feasible?
    if I declare the scope of the bean as the application would I have to put it in all the pages of the web site or not?
    Also, should I just forget about JavaBeans and do Servlets? Maybe EJB is better for this?
    Please provide some examples in your answer if possible.
    Thanks,
    David A

    My question is about high level design. I've written
    some JSP pages and some very simple JavaBeans that
    work on Tomcat.
    Now I'm trying to design a Database access layerThe design and implementation of a persistence layer has nothing at to do with how the data is eventually displayed. Persistence is the same whether you use a Web or a Swing interface, so the question about Tomcat is moot.
    I'd look at Martin Fowler's "Patterns of Enterprise Application Architecture" for its chapter on persistence or the Hibernate object/relational mapping tool.
    I want to have a connection pool class and some other
    business logic classes communicating with each other.Personally, I prefer to let Tomcat handle the database connection pool. I use the Commons DBCP class and configure my connections that way. Then I have my Java code do a JNDI lookup to access them, do the required database operation, and then close the connection to return it to the pool.
    How can I start a bean and keep it running and how do I access its methods from other beans?
    Is this even feasible? I'm not sure I know what you mean by "start a bean and keep it running". HTTP is a request/response, stateless protocol. You should think about operations as being initiated by a request and then going out of scope once the response is generated, much like the protocol itself. You don't keep a bean running in that case.
    if I declare the scope of the bean as the application would I have to put it in all the pages of the web
    site or not?You have to <jsp:useBean> in every page that needs it. Whether or not application scope is really appropriate or necessary is another matter.
    Also, should I just forget about JavaBeans and do Servlets? You can and should use JSP for View, a servlet as your front controller, and JavaBeans to do the work in the back. It's not an either/or question. You really should be using all three.
    Maybe EJB is better for this?You use EJBs if you have a highly transactional, distributed, clustered application. If none of those things apply to you, there's no reason why you must use EJBs.
    Have a look at the Struts and Spring frameworks.

  • Error: EncryptedLocalStore database access error in AIR 3.4

    Hi,
    A few of our users were prompted to update to Adobe AIR 3.4 today. After doing this they were no longer able to use our Adobe AIR "desktop" app. I've downloaded the 3.4 SDK and run our app via ADT and I get the following error in the Introspector:
    Error: EncryptedLocalStore database access error
    Our app stores configuration info in the EncryptedLocalStore.
    This has never occurred before and if I uninstall 3.4 and go back to 3.3 the problem does not exist.  We need an urgent solution to this because we have hundreds of users who use our AIR app every day. We've told them NOT to update to 3.4 until further notice.
    Any assistance would be greatly appreciated.
    Brad.

    Hello AIR developers,
    I want to thank you for your patience and again apologize to you for catching you off guard with this change.  Our team met today and our immediate plan is to roll the ELS changes back to the AIR 3.3 level. We are working on a timeline for when this update will be occur.  We are treating this with the highest priority and expect it will not take long.
    For those interested, here’s how and why this change occurred.  Over the past year or two we’ve heard complaints about the reliability of our ELS implementation, especially on the Mac platform. We’ve known all along that we wanted to refactor this feature and remove dependence on third party libraries.  We undertook this restructuring during the 3.4 release schedule and finished without hearing any major complaints from our internal or prerelease users.  One assumption we made was that ELS data was treated like a volatile cache.  In the past we’ve given guidance on the usage of ELS in both blogs and our help documentation, suggesting that developers should not depend on ELS as permanent data storage because it “can be lost for a variety of reasons”. Our position on this hasn’t changed, but we acknowledge and understand that some applications have come to depend on this data and if at all possible, we should do our best to persist it.
    Going forward, we will most likely reimplement our changes from 3.4, however when doing this we will also work to provide a way to automatically upgrade and persist your application's data.  We will also give plenty of advanced notice and make releases available on our labs.adobe.com site.  We want this change to improve your lives by adding improved stability and we look forward to working with you on this in the future.
    Thanks,
    Chris

  • Question about Database Access

    Hello,
    I have one question regarding database access from Java.
    What are the other ways of connecting to database other than JDBC? This was one of the question I been asked by the interviewer. He says JDBC connection can slow down the perfomance when it comes large number of transactions?
    Any insight or help will be very useful.
    Thanks

    He may have been referring to available "persistance managers" like Hibernate or the mechanisms build into EJB containers. However, as far as I know, they all use JDBC, and any speed-up is due to caching of data as objects.

  • Data access Objects

    Deepak,
    Can you throw some light on the 'Data access Objects" pattern? and how it can be used with Entity beans? I am trying to apply this to the following scenario and having a hard time.
    We need users to be transparent of the data retrieval from various sources like oracle database, flat files or legacy storage. If I use the data access object pattern it is easier to use java classes in place of entity beans.
    Thanks
    Shreyas Kamat

    Shreyas,
    [For those not familiar with our Data Access Object Pattern, the
    beta version of the pattern is available on JDC (needs JDC login) at:
    http://developer.java.sun.com/developer/restricted/patterns/DataAccessObject.html]
    Data Access Objects (or DAOs) are objects that hide the database
    implementation from data clients. Data clients are any objects
    that need to retrieve data from the data source. And the data source
    could be anything that contains data, not necessarily only RDBMSs.
    For example, an external system could be a data source.
    Now using DAOs with Entity beans is applicable only in bean-managed
    persistence (BMP) scenario. In BMP, the entity beans are responsible
    to provide the data load and store implementation in the ejbLoad()
    and ejbStore() methods of the bean implementation. Without using
    the DAOs, the entity bean class will contain all the JDBC code (assuming
    that the data source is an RDBMS), SQL, etc. This makes the
    entity bean class bloated and difficult to manage when changes
    are made to the data logic. In addition, this tightly couples the
    data source implementation with the entity bean implementation.
    By using DAOs, the ejbStore() and ejbLoad() methods are much
    simpler. Also, it is easier to change from one datasource implementation
    to another by replacing the DAOs. Further flexibility is possible
    by employing the DAO factory strategy as described in the DAO pattern
    in our catalog.
    Coming back to you point about making the data access transparent
    to the clients; it is possible to achieve this by using DAO and
    DAO factory strategy. In the current version of the pattern,
    included in the book, we provide sample code to show how
    to design DAO classes and to apply DAO factory strategy.
    On your last point about using java classes instead of entity beans, this
    is not the intention of the DAO pattern. Entity beans serve a different
    purpose in the architecture as coarse-grained transactional components.
    entity beans use DAOs in BMP implementations, but are not replaced
    by DAOs. However, DAO classes are reusable. The same DAO that is
    used by an entity bean to retrieve some data in one application scenario,
    can be reused by a servlet in another application scenario
    that needs the same data, but does not use entity beans.
    So bottom line is that DAOs address the need to data access and
    manipulation and work together with entity beans in BMP implementations.
    thanks,
    -deepak

  • Managed Beans and Data Access Object

    I have a question / need help understanding how to configure backing bean and model objects so that memory and object creation/deletion is done as efficiently as possible.
    1. I have a .jsf page with a form and a commandbutton that submits the form inputs to a backing bean (enrollispbean is backing bean)
    <h:commandButton value="Enter" action="#{enrollispbean.insert}"/>
    2. The backing bean is used for form handling - the insert() method is used to read the data fields from the form and create a SQL string that will be submitted to a model object, DbInsert, that is used as a generic data access object that connects to the database and insert the SQL string:
    public class EnrollIspBean {
    private String beanvar1="";
    private String beanvar2= "";
    // DbInsert is data access object
    private DbInsert dbinsert = new DbInsert();
    public String insert (){
    String sqlstmt;
    sqlstmt = "INSERT INTO ispmain VALUES(beanvar1, beanvar2,..)"
    dbinsert.insert(sqlstmt);
    return "success"; }
    3. DbInsert is the data access object that contains a method, insert(), that accepts a sql string to insert into the database. This method contains the code to obtain a connection from the database connection pool and then execute the sql statement (note: error checking code not shown):
    public class DbInsert {
    public void insert(String sqlstmt) throws SQLException {
    Connection conn = null;
    GetDBConnection getdbconnection = new GetDBConnection();
    PreparedStatement stmt = null;
    conn = getdbconnection.getdbconn();
    stmt = conn.prepareStatement(sqlstmt);
    stmt.executeUpdate();
    stmt.close();
    conn.close();
    return;
    Where I need help understanding is how to set up the scope for the managed beans and data access object. Currently, I have the backing bean within the session scope (using the facesconfig.xml file). My main question is how to set up the scope for the Data Access Object - currently I do not have it as a managed bean within facesconfig.xml. Instead I am creating a new instance within the backing bean:
    private DbInsert dbinsert = new DbInsert();
    Is this the best way to do this? Will the DBInsert object now be tied to the session scope of the backing bean (i.e., when backing bean is deleted, the DbInsert object will be deleted from session scope as well.)
    Ideally I would like the data access object to be available as a shared object throughout the life of the application. When I was programming using a servlet approach, I would have created a servlet to load on startup. Now that I'm using java server faces, I'm confused about the scope / how to efficiently set up a data access object that I want to be available to all backing beans in the application.
    tnanks for any help understanding this.
    Tom

    I was thinking about setting the data access object as application scope so that it can be used by an backing bean to execute sql statements.
    If I do set it as application scope, however, if I do this, do I still need to declare a new instance of the object from within each bean that uses the object?
    For example do I need to declare a new instance of the data access object from within the bean? or, should I assume that there is always an instance of the bean available in the application scope, and if so, how do I reference it from within the bean?
    Bean Code:
    public class EnrollIspBean {
    // DbInsert is data access object
    private DbInsert dbinsert = new DbInsert();
    Finally, I understand performance may be an issue if I have one instance of the data access object available in the application scope - is there a way to make multiple instances available in the application scope?
    thanks

  • Accessing objects from an existing JVM on Windows

    I have a Java class that is running in an existing JVM which is running on local windows workstation. Is there a way I can access any methods or objects from the running Java class and other objects running inside the JVM from C or C++ code using Invocation API?. I know there is a way for us to ATTACH to a JVM that was created from C/C++ but I am looking for a way to access objects from a JVM that was started either as a service or started by other means.

    How did you start the C++ code?
    It is possible to load the c++ dll within your Java code then you may access the c++ code by using native methods out of Java. By calling the c++ method you have the pointer to your Java object and my use it (=> don't forget to use global references).
    If you have started both seperatly C++ in an extra process and Java in an extra process then it can be complicated. Guess that there aren't any easy solution.
    This mean: either you have your Java code loading a dll or you have C++ creating a JVM...

  • How do i store and fetch image from the Database(Access)

    i am facing one problem in inserting the image into the database.the steps i followed as
    1)i have created one database(access) as "Image" and into that one table as "Image" and field as "image"
    type of the field is ole object.
    2)i have inserted one image into the image field through "database.vi"
    3)now i am trying to get the image from the database by "Fetching Example.vi"
    4)it will succesfully retrieve the image from that field .
    5)but when i close the both programs and reopen those that time i am unable to get retrieve the image.
    Attachments:
    Add_to_Database.vi ‏78 KB
    Fetch_from_database.vi ‏67 KB

    I would like to suggest different approach for saving the images in the database.
    I was working on Medical Imaging Company. The way we save the images in real-time was by writing the name and path of the images to database.
    The images themselves where saved directly to disk.
    I don�t think that access is very good in taking care of GBytes of data.
    It happens some time that the database gets damage. If you have the images separately you can create fix procedure. (We had one).
    Good Lack,
    Amit Shachaf,

Maybe you are looking for

  • Batch with classification at the time of inbound delivery

    Dear all, How do I create batch with classification at the of inbound delivery. Thanks in advance Mrinmoy Chakraborty

  • HT3704 change position of image in table

    How can I fine tune the position of an image in a table? I've got two documents. In one I can go to the inspector mode and presicely set the x and y value. Then I've got the other document, same image, and in the inspector mode, I can't set the x and

  • Email in Text and Hmtl

    I am receiving all incoming email in text and Hmtl. I only want to see them in plain text. How do  change this?

  • On cascade delete

    I have two table profile and salary. salary.id is the foreign key of profile.id. During the creation of table I haven't called on cascade delete. Now I want to delete a row from profile.id, which will not delete because primary.id has been used in sa

  • Want BAPI for MC93, AND MC94

    Hello, Plz any one let me know the BAPI(Business object) for MC93 or MC94 to record data for planning type. Regards Martin