Servlets and Persistent Database Connections

I'm looking at building an application using
java Servlets.
My Application will consist of many individual Java Servlets.
I want to ensure that there is a persistent database connection so that the users do not have to log on again when a page generated via Servlet1 contains a URL to Servlet2....
null

Look at the Http session class in the Servlet specification. It will maintain state for you across client requests.

Similar Messages

  • When to open and close database connection

    im trying to connect to a oracle database using servlets
    when should i open and close the connection
    it works fine when i do both in the doPost() method
    but when i tried to open connection in init() methd .. it doesnt seem to work
    what should i do...
    the connection is initialised in the init() method but is null in the doPost() method

    " im trying to connect to a oracle database using servlets
    when should i open and close the connection
    it works fine when i do both in the doPost() method
    but when i tried to open connection in init() methd .. it doesnt seem to work
    what should i do...
    the connection is initialised in the init() method but is null in the doPost() method"
    1:
    without seeing the code i would say the the connection is null
    because you are storing it as a servlet class variable which is
    not thread safe.
    2:
    The best way to do it using connection pooling
    detailed docs on the tomcat website
    3:
    if you are not using connection pooling, then
    open and close the connection in the do* method
    or
    use init() to place the connection in the servletconfig
    and close in destroy() and use synching to access

  • Persist Database connection over user's session

    On portal 3.0.9 with JPDK v1 I have a web provider that has a jsp portlet. The portlet has multiple pages which are navigated useing a parameter specified with the pageParameterName tag in the provider.xml. Each page needs to be able to access the database and to allow a rollback for all a users actions until a certain page is visited I need a way for all the access to be done through one database connection.
    Putting the dbOpen tag in the event:session_OnStart tag of my globals.jsa file doesn't work (I'm not sure the event:session_OnStart is even executed) and trying to create the connection once with the scope="session" creates an error. Any help would be appreciated.

    Generally speaking, persisting a connection over a users session is a BAD idea. If you really need to do it you simply be able to add the Connection object to the session. However, I would strongly recommend that you review your model because it will not scale.

  • Servlets and multiple JDBC connections...

    Hi Guru's
    I want to perform multiple JDBC queries simultaneously from my servlet. Let's say I have a connection pool containing JDBC connections. Now what I want to do is to use each of this connections simultaneously to perform queries in parallel.
    What is the best way to do this??? create multiple threads, one for each query, and then collate results when all threads are finished???
    Has anyone does this before or know of any links or samples which I can look at??
    your help much appreciated...
    Many Thanks

    Thanks but further questions....
    But take care:
    multithreading might only work parallel if there are
    multiple processors - otherwise the thread fragments
    will be processed one after the other until they are
    finished.I agree. My server has multiple processors hence multi-threading.
    Why do you need to perform the queries
    simultaneously?
    wouldn't it work too when you perform the queries one
    after the other?To speed up performance. Sequential processing is too slow at the moment.
    Hope you don't try doing so inside one single
    database...yes inside a single databse.
    Do you have any links to sample example etc..??? Importantly are you aware of any issues when one does this type of multi-threading from servlet. i.e does it clash with servlet's threading model etc...
    I am aware of how servlets multithread requests and am quite familiar with them. Just wanted some examples on multithreading JDBC connections from servlets and how I can wait for all threads to finish before collecting results....also wanted to make sure that there are no other issues....
    further help will be much appreciated.....

  • Open and close database connection jsp page

    hi there, i wanna know about how to open database connection to Mysql at the beginning of the page and close the connection at the end of the page. The jsp page contain all processing code.
    plz help me...thx thx

    <html>
    <head>
    <basefont face="Arial">
    </head>
    <body>
    <%@ page language="java" import="java.sql.*" %>
    <%!
    // define variables
    String id;
    String firstName;
    String lastName;
    // define database parameters, change this according to your needs
    String host="localhost";
    String user="root";
    String pass="";
    String db="test";
    String conn;
    %>
    <table border="1" cellspacing="1" cellpadding="5">
    <tr>
    <td><b>id</b></td>
    <td><b>first name</b></td>
    <td><b>last name</b></td>
    </tr>
    <%
    Class.forName("org.gjt.mm.mysql.Driver");
    // create connection string
    conn = "jdbc:mysql://" + host + "/" + db + "?user=" + user 
    + "&password=" + pass;
    // pass database parameters to JDBC driver
    Connection Conn = DriverManager.getConnection(conn);
    // query statement
    Statement SQLStatement = Conn.createStatement();
    // generate query
    // change this query according to your needs
    String Query = "SELECT id, firstname, lastname FROM abook";
    // get result
    ResultSet SQLResult = SQLStatement.executeQuery(Query);
    while(SQLResult.next())
       id = SQLResult.getString("id");
       firstName = SQLResult.getString("firstname");
       lastName = SQLResult.getString("lastname");
            out.println("<tr><td>" + id + "</td><td>" + 
         firstName + "</td><td>" + lastName + "</td></tr>");
    // close connection
    SQLResult.close();
    SQLStatement.close();
    Conn.close();
    %>
    </table>
    </body>
    </html>hi :-)
    i've got that on the net as part of the tutorial on jsp (long long time ago)
    you just have to be resourceful in finding solutions :-)
    try google :-) there are lot's of tutorial available in there ;-)
    goodluck ;-)
    regards,

  • Production and Development Database Connections

    Within JDeveloper I have created a database connection to a DEVELOPMENT database and am exposing PL/SQL packages in the development database as web services.
    I can develop and test successfully the exposed packages as web services, and can deploy and run them to a standalone OC4J container on my local machine.
    I then handover the generated EAR file to the production team who deploy the EAR as a web service to the Oc4j container in a remote 9i Application Server.
    This runs successfully from 9iAS.
    So far so good.
    If I have the same PL/SQL package in a live database and development database, but only have access to the development database, how can I expose the package in the live database?
    Can I have a database connection in JDeveloper with a connection name pointing to the development database connection, and have a connection defined in 9iAS with the same name pointing to the live database?
    Any information will be useful.
    Thanks,
    Claire.

    Per the J2EE "roles" definition this is a deployment role todo.
    I.E. the theory is; take a 3rd party ear, depoyee with your appserver vendor's
    deployment tool, edit the data-sources.xml imbeded in the ear on the fly, as
    deployment happens.
    Bake to reality-
    OC4J 903 is intended to be used with OEM for the J2EE spec'ed role of deployer. I'm
    headed this way, but not started the 903/OEM todo.
    Today, OC4J 902 and 902 Jdev, I deploy to a local instance of OC4J. I take that
    ear to production. I've written procedural instructions on poping open the ear and
    editing the data-sources.xml for the DB connection URL and possible login/passwords.
    BTW all your AppModule configurations will have to use data-sources DB connections else
    you'll have DB connection info littered in your bc4j.xcfg's for each AM deeper in your war's.
    I'd like to hear how this is supposed to work from some other folks? :)
    Good luck,
    curt

  • Overly Persistent Database Connections

    When we "disconnect" a connection, is it truly gone?
    Because I'm thinking it may not be really gone until we leave sql developer.

    Finally had a chance to properly test this.
    The connections do appear to be removed upon disconnecting.
    However, I experienced a number of "false disconnects".
    By that, I mean, I told sql developer to disconnect from a connection, saw no warning/error message saying it did not disconnect, but the disconnect did not take place. The connection remained in effect and the connection list in the tree continued to show it as connected.
    On several occasions, I told it to connect but it did not. Ditto for lack of warning/error message and for the connection tree showing it as disconnected.

  • Crystal Reports and Access database connection error

    I had this in a different forum with no hits, so I am trying this one.
    A person that I work with has multiple reports set up that pulls from an Access database that is password protected. When we moved everything over to a new computer, those reports now say that it cannot access the fields inside the database. It never pops up with a login screen either, like it does on the old computer. I played around with the ODBC, with no luck, couldn't get anything to work. I have also tryed relinking the database, but I keep getting connection problems. We are on a network, so her settings should have all moved with the new computer. Along with the database and the reports being on the server, so they were never moved. I am thinking it has something to do with a system file.
    I also found this document on this site, but cannot find the download it mentions, sounds similar to my problem.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/208b8fe5-681e-2b10-d2bb-b201f266d0ab
    Does anybody know how to fix this without the utility mentioned in the above link, or know where I can get the utility??
    We are using Access 2007 and Crystal Reports 7.  The database is not save as an Access 2007 database, but a regular mdb.
    Please Help!

    Post Author: ejthunder
    CA Forum: Crystal Reports
    Hello Chris,
    Crystal Reports does not store the database password with the RPT file.  This is by design (Crystal is not a database security product).  This is true of all versions of Crystal Reports.
    If your users need to see fresh data when opening the reports then they will have to log in by providing at least the password.
    You can send reports with Saved Data that won't try to hit the database, but the data won't refresh either.  To save data with the report go to the File menu and click next to Save Data with Report.  Refresh the report and then save it.  The report will now have saved data and won't try to hit the database when opened.  If the user hits the refresh button then they will get prompted to log into the database.
    I hope this helps.
    EJ

  • J2ME and PHP DATABASE CONNECTION

    Hi ALL
    I am writing an application that need to pull information from a database. I have a Tomcat server set up. I am using MySQL as my database. I was planning to use PHP to pull information from the database. I just do not know to use J2ME with PHP. In other words once I pull the desired information from the database how do would I then display it using J2ME. Does any one have any good books or web references, where I can begin to start looking.
    Thanks for your help

    I have created a solution with the exact configuration you describe (www.i2score.com in swedish). You dont have to use J2ME with PHP. They work independetly from each other. My J2ME Midlet serialize and de-serializ the information, communicate via HTTP to the Java servlets running on the Tomcat server. The servlets put and get info from the MySQL database.
    On the same server (could be a seperate if you want) PHP pages with MySQL coupling is used for web access to information on the same database but put and get. Very neat in my opinion. Good luck with your project. Be more precise with your roblems if you want more help.

  • Weblogic and lost database connection

    Good Morning,
    I'm working with Weblogic, connecting to an Oracle database on a rather unstable network. From time to time, the connection to the database is lost, and at the moment, this means having to restart weblogic.
    Is there any way to configure weblogic to automatically reconnect to a database if the connection is lost and then restoired?
    Thanks in advance for your help.

    this forum is about Sun's J2EE sdk/application server.

  • How to keep the worksheet and the database connection in sync

    Is there a way I can configure sqldeveloper to do this
    - I click on a worksheet
    - The specific connection in the "connections list" on the left get highlighted
    - The specific connection if not expanded gets expanded
    Basically I want the sql worksheet and its connection to be always in sync
    I am using sqldeveloper Version 2.1.0.63 Build MAIN-63.41 on Windows XP
    -Nags

    No, but it'd be nice. I recommend adding it as a feature request @ http://sqldeveloper.oracle.com and have people vote on it. It

  • Lan Database and Wireless Database Connectivity and Settings

    Some one help me that what the difference in LAN connectivity and connectivity over a wireless network.
    Is any difference. If difference than please send me some material to understand this.
    Thanks

    From the Oracle perspective, there is no difference where the communication comes from, as long as access through a supported protocol is established. So, from this perspective, all rules that apply to regular connectivity applies to wireless.

  • How to use sql request with Jdev and database connection

    Hello,
    I have a login page with simple username and password inputsecret text and a button validate! I would like, when the user click on the validate button, to check in the database that the user and password matches. I've done the "Method BIndind..." with the commandButton_action and the database connection works fine.
    How can I use an already existing procedure, say authenticate, wich is stored in the database to authenticate my user ?
    Do I have to create a jdbc connection in java even if I've done the connection with the "create new database connection" wizard ?
    String s1 = "jdbc:oracle:thin:@address:1521:ORCL";
    System.out.println( "Connecting with: " );
    System.out.println( s1 );
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    this.conn = DriverManager.getConnection( s1,"user","pass");
    thanks for your help

    Creating a connection to the DB in JDeveloper doesn't mean that your application is now connected to the DB - so yes you do need to create a connection to the database using JDBC.
    One note - if you are trying to do a database user authentication the following is probably the better way to go about it:
    http://www.oracle.com/technology/products/jdev/howtos/1013/oc4jjaas/oc4j_jaas_login_module.htm

  • OLE Objects and Database Connectivity Toolkit

    I am trying to insert and image (jpg) that is created in Labview into an Access database as an OLE object. How do I go about making this conversion, or are there any other suggestions?

    Hello -
    Have you tried any of the shipping examples for the database connectivity tookit? You can find them by navigating Help >> Find Examples >> Toolsets and Modules >> Database Connectivity. The Insert Example.vi may help you get started. Click here to access database examples posted on the Developer Zone.
    Please let me know if any of these examples helped. If not, can you provide more information about the version of LabVIEW and Access you are using? Thanks! Have a great day!
    Becky B.
    Applications Engineer
    National Instruments
    Becky Linton
    National Instruments
    Field Engineer
    Office: 734-464-2463
    Cell: 248-709-2822
    Email: [email protected]

  • Problem with having several database connection registered in JDEVElOPER

    Hi
    Thank you for reading my post
    I have several AS registered in my Jdeveloper environemtn and several database connections.
    unfortunately some times Jdeveloper can not deploy an application into a server beacause it say that "I failed to create the connection pool", the project has no database stuff at all but Jdeveloper try to register and create connection pools for those connection that i hace registered in the Databse coonnection node.
    It fails because in that particular server which i want to deploy the application i have not add all databases JDBC driver.
    is there any solution for it?
    thanks

    Hi,
    see Tools --> Preferences --> Deployment
    Uncheck the "Bundle default data-sources.xml during deployment
    Frank

Maybe you are looking for

  • Process Chain takes alonf time to run

    Hello All, We have a process chain which loads data for texts, attributes etc. On certain days the process chain will run extremely fast and maybe take a couple of hours, other days the same process chain may take 24 hours to run.  It appears to get

  • How to transfer a TV show episode rented in iTunes 10 to Apple TV 1st Gen?

    I've rented an HD pilot episode of "Lie To Me" show on my PowerBook in iTunes 10. Unfortunately, the video is very choppy (it's only a 1.5 GHz G4) and I'd like to transfer the episode to my Apple TV. I've read about how to do it, went into the device

  • ERROR ITMS-9000: "null" at Book (MZItmspBookPackage)

    I'm using latest Mac with all updates complete. Created a free book on Author. Preview has no issues. Everything runs smooth up until the delivery stage. I have been roaming at forums and everywhere Google gives me a link without any success. No expl

  • Getting 'java.lang.OutOfMemoryError' while importing process flows.

    Hello, We are getting 'java.lang.OutOfMemoryError' error while importing process flows in our QA environment. This environment is not new. The same process flows were working perfectly fine till last week. This week we had to delete the project in QA

  • InterMedia Java Servlet photo album sample application

    O/S Microsoft 2000,oracle 8.1.7 PROBLEM IS HAVING CONFIGURRED ALL THE PARAMETERS AS DEFINED IN THE READ ME FILES AND HAVING COMPILED THE CODE TO GENERATE THE CLASS FILES AND PLACED THEM IN THE SAID FOLDERS THE ERROR FOR JSP AND THE SERVLET EXAMPLE IS