General Design With Database and Session Bean Question

I have an application I am developing where users connect to individual databases located on a server. When they login an admin table is accessed which shows what databases they have permissions to. I am then storing the connection to the database in a backing bean. Hoping to use this connection throughout the session. Is this a good practice to have a users connection left open over the session? I can't create a database pool for each individual database and each user for that database.
If I can store that database connection in a session bean. How do I access that connection from another bean. Or from another java class? I am using Glassfish for my application server with JSF1.2. I have looked at resource injection but have not had any luck with sharing the session bean information.
Sorry if this is a trivial question. I have been a Java developer for years. But just starting developing webapps using JSF.
Thanks

JuCobb2 wrote:
I am then storing the connection to the database in a backing bean. Hoping to use this connection throughout the session. Is this a good practice to have a users connection left open over the session? No it is not. Why should you do so? Always keep the lifetime of connection, statement and resultset as short as possible.

Similar Messages

  • Can I connect with Database using Session Bean

    Hi,
    I am new to EJB. I have small doubt.
    can I connect with Database using Session Bean.
    Regards,
    Murali.

    Double post of http://forum.java.sun.com/thread.jspa?threadID=687239&tstart=0

  • Is it possible to connect database using session bean

    Dear all,
    Is it possible to connect database using session bean without using entity beans like cmp,bmp.
    if ur answer is yes, then pls tell me where to put the select statement and transaction attribute like(6 types).
    if u have sample code, then it is good for me.
    Hope I will get answer.

    Sure it is.
    Try something like this (and maybe get a book on JDBC):
    String name;
    try {
         InitialContext ic = new InitialContext();
         DataSource ds = (DataSource) ic.lookup(Constants.MY_DATASOURCE);
         Connection connection = ds.getConnection();
         String sql = "SELECT * FROM TABLE";
         PreparedStatement statement = connection.prepareStatement(sql);
         ResultSet rs = statement.executeQuery();
         while (rs.next()) {
              name = rs.getString("NAME");
         if (rs != null)
              rs.close();
         if (statement != null)
              statement.close();
         if (connection != null)
              connection.close();
    catch (NamingException e) {
         // Can't get JDBC datasource
         // ... do something with this exception
    catch (SQLException e) {
         // SQL exception from getter
         // .... do seomthing with this one too
    }

  • Entity Beans and Session beans to represet Business lOgic

    How cam we implement Entity Beans and Session beans to represent Business Logic.
    Can anyone explain how can we do this.
    Regards...

    I have session beans calling method in entity beans and any client
    doesn't have access to entity beans, only via session beans.
    If i define security policy and method permissions for session beans
    only, do entity beans use that permissions when calling their methods
    from sessions beans OR should i define the security policy for entity
    beans separately?If you want to set the permission on individual
    methods of entity bean ( with different roles)
    you have to do it separately.
    If you want to delegate the Authenticated user along with
    the method call to the Entity Bean you can use
    run-as-identity-principal.
    For more detail please check out the EJB2.0 Spec.
    -utpal

  • How to master good design with EJB and JSP?

    I use JSP to calling EJB. But the .jsp file is complex and it's difficult to maintain...I just want to work higher efficent with EJB,JSP and JavaBean. I want to know is there a good design with EJB and JSP? and is there any good material about MVC for EJB,JSP and JavaBean?

    You should read the J2EE blueprint available on this website. Better download the PDF, and print it for yourself so you can read it anytime.

  • When I design with Muse and export as HTML Dreamweaver doesn't attach the style sheets. Any answers?

    When I design with Muse and export as HTML Dreamweaver doesn't attach the style sheets when I open the files with Dreamweaver. Essentially when I design with Muse the files don't render the same with Dreamweaver. Is this a bug? Any work arounds?

    Then you will have to install a local server and use live view.  It's not that DW isn't rendering it or isn't attaching it, it's that Muse decided to use server-side processing to include it which is ok for a CMS practice when you are combining stylesheets for better caching, but it really isn't ideal for a single style sheet.  This is a shortcoming of Muse and one of the reasons many professionals don't back the product at the moment.  That and you can't actually buy Muse, so unless you are on a subscription you don't have it.  It's trying to fill a void for those who don't want to invest in the professional design tools like Fireworks or Photoshop or Dreamweaver, but want a cross between them to make designs.  If you have invested in the subscription though and want a better way to make layouts I highly recommend coding it yourself and using Fireworks or Photoshop to do the layout for you.  There is an excellent tutorial on the devnet (3 parts) to show you how its done ( http://www.adobe.com/devnet/dreamweaver/articles/dw_fw_css_pt1.html ).  Once you start using Fireworks or Photoshop you will realize just how limited Muse is in design.

  • Oracle 10g RAC design with ASM and OCFS

    Hi all,
    I have a question about a proposed Oracle 10g Release 2 RAC design for a 2 node cluster.
    ASM can store database files but not Oracle binaries nor OCR and voting disk. As such, OCFS version 1 does not support a shared Oracle Home. We plan to use OCFS version 2 with ASM version 2 on Red Hat Linux Enteprrise Server 4 with Oracle 10g Release 2 (10.2.0.1).
    For OCFS v2, a shared Oracle home and shared OCR and voting disk are supported. My question is does the following proposed architecture make sense for OCFS v2 with ASM v2 on Red Hat Linux 4?
    Oracle 10g Release 2 on Red Hat Enterprise Linux Server 4:
    OCFS V2:
    - shared Oracle home and binaries
    - shared OCR and vdisk files
    - CRS software shared OCFS v2 filesystem
    - spfile
    - controlfiles
    - tnsnames.ora
    ASM v2 with ASMLib v2:
    Proposed ASM disk groups:
    - data_dg for application data
    - backupdg for flashback and archivelogs
    - undo_rac1dg ASM diskgroup for undo tablespace for racnode1
    - undo_rac2dg ASM diskgroup for undo tablespace for racnode2
    - redo_rac1dg ASM diskgroup to hold redo logs for racnode1
    - redo_rac2dg ASM diskgroup to hold redo logs for racnode2
    - temp1dg temp tablespace for racnode1
    - temp2dg temp tablespace for racnode2
    Does this sound like a good initial design?
    Ben Prusinski, Senior DBA

    OK Tim, thanks for advices.
    I think Netbackup can be integrated with RMAN but I don't want to loose time on this (political).
    To summarize:
    ORACLE_HOME and CRS_HOME on each node (RAID1 and NTFS)
    Shared storage:
    Disk1 and disk 2: RAID1: - Raw partition 1 for OCR
    - Raw partition 2 for VotingDisk
    - OCFS for FLASH_RECOVERY_AREA
    Disk3, disk4 and disk5: RAID 0 - Raw with ASM redundancy normal 1 diskgroup for database files.
    This is a running project here, will start testing the design on VMware and then go for production setup.
    Regards

  • Probleme with transaction in session beans

    Hello.
    i create an session bean which call enties beans.
    When i execute un example first time, its correct.
    when i execute for second time, the methode don't stop.
    i think it is problem of transaction.
    thank you

    Hi,
    It is impossible to answer your with the given information. When ever you are asking a question please put the relavent informatin like code and deployment descriptors. So please do post the required information.
    Ashok

  • Refresh code servlet and session bean don't work more.

    Hi all,
    I'm not sure if it's a problem with oc4j, but maybe someone can
    help me.
    I'm working with Jdev 10.1.3.0.4(SU4) on Fedora Core 5 and XP.
    I create an application with a servlet, ran the servlet and
    all things work. Change the code in servlet, recompile and refresh
    the browser and all work fine.
    But, when I create a CMP Entity Beans from Tables with EJB 3.0 on
    a simple table and change the code in servlet, recompile and refresh
    the browser the code of servlet stay old. Just restart oc4j make the changes
    work. Changes on entity bean ou session beans or junit class take
    the same problem, just after the restart oc4j do the job.
    Is it a bug? Is thera a workaround?
    Thanks for all,
    Luciano

    Oh and before you tell me to just use XSLT on the output to get it how I want it, or use XMLType views where the XML is generated on the database server, I can assure you I know both of those options, but they both cut into the profitability of running a high-volume service.
    The XSU (XML SQL Utility for those keyword searching) is great in that I can host it on middle tier servers in any servlet container and take the burden of XML generation and parsing off the $40K/processor server. If I can further take the burden of XSLT transformations off the middle tier, so much the better... The XSU allows me to run the same throughput on probably something like half the hardware and a tenth the licensing fees.
    So here's a huge vote in favor of continued development of the XSU...I would also like it to handle XML attributes on inserts/updates rather than having to use the "canonical" element form.
    If anyone knows an even better approach, please speak up!

  • Problem with JMS from session bean

     

    My guess is that in your effort to work around the
    clustering/ejb/jndi problems, you have a producer
    sending on one topic, and a consumer listening on
    another topic. You can check to see if they are the
    same destination using the (uncompiled) code snippets
    below at both the producer and consumer ends.
    import weblogic.jms.common.DestinationImpl;
    Topic topic;
    DestinationImpl destination = (DestinationImpl) topic;
    System.out.println("name = " + destination.getServerName() + "/" +
    destination.getName());
    System.out.println("back-end id = " + destination.getBackEndId());
    System.out.println("destination id = " + destination.getDestinationId());
    _sjz.
    "Malcolm Robbins" <[email protected]> wrote in message
    news:[email protected]...
    >
    This was also posted to the EJB newsgroup and was asked to post the secondissue
    here. Please focus on the second issue, but the first providesbackground.
    >
    >
    I have discovered two significant problems in WLS6.0 with JNDi and JMSthat do
    not occur in the Sun Reference implementation (1.3 Beta).
    Attached is some code you can try to see the problem.
    I have developed a JmsClient that simply looks up a session bean andpasses it
    a string to publish. The session bean is meant to publish to a JMS topic.
    However I have discovered two problems:
    1) In teh ejbCreate() method I look up the topic connection factory andtopic
    in JNDI. These are referenced as "java:comp/env/jms/JmsConnectionFactory"and
    "java:comp/env/jms/JmsTopic" respectively. Here's a fragment of theejb-jar
    descriptor
    <resource-ref>
    <description>The (probably durable) Topic Connection Factory to connectto</description>
    <res-ref-name>jms/JmsConnectionFactory</res-ref-name>
    <res-type>javax.jms.TopicConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    <resource-env-ref>
    <description>The Jms Source Topic to publish to</description>
    <resource-env-ref-name>jms/JmsTopic</resource-env-ref-name>
    <resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
    </resource-env-ref>
    As you can see they are resource references and resoruce environmentreferences
    respectively. The weblogic-ejb-jar maps these to the real JNDI names"TopicConnectionFactory"
    amd "SchemaTopic" respectively as shown below by the fragment:
    <weblogic-ejb-jar>
    ...etc...
    <reference-descriptor>
    <resource-description>
    <res-ref-name>jms/JmsConnectionFactory</res-ref-name>
    <jndi-name>TopicConnectionFactory</jndi-name>
    </resource-description>
    <resource-env-description>
    <res-env-ref-name>jms/JmsTopic</res-env-ref-name>
    <jndi-name>SchemaTopic</jndi-name>
    </resource-env-description>
    </reference-descriptor>
    Now here's the first problem. When this is deployed the resourceenvironment
    "logical" name (JNDI linkref) for the topic is not defined. The code willhappily
    find the connection factory (presuming you've set these administeredobjects at
    the console).
    2) The second problem now arises. In the code I have ahcked it so thatwhen
    the JNDI lookup fails it tries looking up the real topic in JNDI(SchemaTopic)
    directly.
    This works and teh bean now appears to work, albeit with a directlyhardcoded
    JNDI reference in it. However, if you hook up a standard JMS consumer tothat
    topic it will not consuem the message that is published!!! While thestats clock
    up at the console the message appears to go into a black hole. I canprovdie
    a stadnard consumer if you need one.
    I have the code working fine as-is in teh Sun Reference implementation soI presume
    these are bugs with WL6.0.
    Can anyone advise workarounds and/or fix the problem?

  • When to use ApplicationBean  and Session Bean dataproviders

    hi i am developing a small application, in which i have cached rowset and if i want to access the database i have to call the bean component so which one to call either application Bean or Session Bean component in some examples they used application bean and in some applications they used session bean. Please suggest me the right one and i have to access the database correctly. I am confused ,please help me out in solving this problem.
    Thanking You in Advance.

    The following excerpt is from http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/scopes.html
    Before you create a bean property to store a value, you must decide what scope to put the property in. Because several users can access a web application at the same time, you want to use the smallest scope possible so that you don't waste valuable space. The following figure illustrates the duration of each type of scope.
    * Application scope lasts until the server stops the application. Values that you store in an application bean are available to every session and every request that uses the same application map.
    * Session scope begins when a user first accesses a page in the web application and ends when the session times out due to inactivity, or when the web application invalidates the session, such as, for example, by calling session.invalidate().
    * Request scope begins when the user submits the page and ends when the response is fully rendered, whatever page that is.

  • Session bean question

    I am very new to java and I am learning struts using websphere.
    I have a bean that I want to make available as a session bean so I don't have to run my query to populate the bean everytime I need the data. I have never done this before and would like to know how.
    In my first action after creating the bean I did this to try to make it a session bean
    HttpSession session = request.getSession();
    UserBean ub = (UserBean) session;
    is this right?
    Also if I want to use this session bean in other actions do I need to have getters and setters for the bean in the new actions action form?
    Also how do I call / invoke the data out of this bean in the other action?

    I think you are trying to mix 3 things together: EJB session bean, HttpSession, and JavaBeans. Your UserBean seems like a JavaBean. The above three are totally independent of each other.
    JavaEE tutorial may be of help:
    http://java.sun.com/javaee/5/docs/tutorial/doc/

  • EJB 3.0 Session Bean question

    Hi there,
    How'd I expose a method of Stateless Session Bean in EJB 3.0? I don't seem to find any annotation for that.
    Thanks in advance.
    Saeed

    If you need to expose method implemented in Session bean, you can invoke the method call from within another method called in Client.
    This method has to be defined in the remote interface . The method you are trying to invoke can be defined somewhere else but called in your bean class from within the method definedin the remote interface.

  • Stateful Session Bean Question

    I have a stateful session bean being invoked by my web tier on several request/response transactions. What would be the best way to locate the same session bean ? Would that be the create method in the Home i/f or would i need to supply a finder method for locating an existing bean?

    Hi,
    Store HomeObject or EJB Object in the Session in the WebTier.
    Anil

  • Hi nid help with database and web

    hi to all! i wanted to get some help on how to connect to a database in a web... i dont know if its javascript,java applet,or jsp... could some1 pls give me a code on how to make a simple login database connection in a web through java.. i really nid it guys... we have our contest next week... pls.. i really nid your help... tnx!

    hi to all! i wanted to get some help on how to
    connect to a database in a web... what do you know about databases and the web today?
    i dont know if its
    javascript,java applet,or jsp... yes.
    could some1 pls give
    me a code on how to make a simple login database
    connection in a web through java.. (1) create a table USER in your favorite relational
    database - id, username, and password should be
    enough.
    (2) Use HTML to create a login form - username and
    password text fields and a submit button will be
    good.
    (3) Write a JSP using JSTL <sql> tags to query the
    database and put the result into request scope.
    (4) Redirect to a success JSP to demonstrate a
    successful login, or back to the login if it fails.
    i really nid itI hope this helps.
    guys... we have our contest next week... pls.. i
    really nid your help... tnx!What do "we" win? Will you be listing me as the sole
    developer if I write this for you?
    My rate is $120 USD per hour. Give a credit card
    number and I'll get right on it.<Actually its just a contest for our intramurals.. i was just hoping if u guys could help me ... thnx!

Maybe you are looking for

  • Mac vs PC: bus bottleneck in Mac?

    I am a long time Mac user considering an upgrade to a Mac Pro for photography and soon for video and gaming. A photographer friend familiar with both Macs and PCs told me that I should consider the PC option for resource intensive applications as Mac

  • Calling a stored procedure from Reports

    I am trying to call a stored procedure using oracle reports in the afterparameter code. My code is: v_ain := sp_get_ain(:P_session_id); Can someone help me out by telling what is wrong. I keep getting an error stating that sp_get_ain needs to be decl

  • Flat File reconciliation failing with no error

    Hello, I'm trying to set up flat file reconciliation with OIM 11g. I've followed this guide http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/oim/10.1.4/oim/obe12_using_gtc_for_reconciliation/using_the_gtc.htm and configured the mapping f

  • Compilation error occurred

    i get this error when i try to deploy a web service. is there a way to debug the oc4j compilation process? it's behaving VERY strange.. everything is ok if the webmethod is returning a class of name: "Class1", but if i rename it to "HolidayDto" i get

  • G5 Won't Reboot Since WD Caviar Installation

    I bought a WD Caviar Green 1 TB internal drive and installed it myself. I followed every step, carefully installed the drive, discharged static, etc., and turned on the computer. The fans kicked in like crazy and I got the ? of Death. Long story shor