Will the statement object be alive???

Take a look at the code below::
methodX(){
Connection conn = null;
try{
conn = getConnectionFromDbPool();
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("some query");
}catch(SQLException e){
e.printStackTrace();
}finally{
conn.releaseConnectionToPool();
I'm getting the connection froma pool of live connections. I create a statement object locally in the try-catch block. run some query. Then in finally i'm releasing the connection back to DB pool and NOT closing it.
So, will the statement object created with the connection be still alive or since it was created in a local block it will be garbage collected by java????

What do you mean "get the statement objects a connection has"? You shouldn't need this. Your earlier posted code simply needs to be slightly modified as follows:
Statement stat;
ResultSet rs;
try{
  conn = getConnectionFromDbPool();
  stat = conn.createStatement();
  rs = stat.executeQuery("some query");
  // process ResultSet
} catch (SQLException e) {
  e.printStackTrace();
} finally {
  if (rs != null) rs.close();  // check only needed because createStatement might throw an Exception (should never happen)
  if (stat != null) stat.close();  // check only needed if getConnectionFromDbPool might throw an Exception
  conn.releaseConnectionToPool();
}

Similar Messages

  • Error: The report source could not be retrieved from the state object.

    I have been trying to create a report in a JSF page. The relevant parts are below:
    Inside the JSP page, this is the code:
                  <jsp:useBean id="MyBean" class="com.nm.facade.rto.POJOViewerBean" scope="session" />
                    <jsp:setProperty name="MyBean" property="reportLocation" value="Report1.rpt" />
                   <v:reportPageViewer reportSource="#{MyBean.reportSource}"
                                           displayToolbarPrintButton="true"
                                           printMode="ActiveX"
                                           zoomPercentage="100"
                                           displayToolbarExportButton="true"
                                           displayToolbarRefreshButton="true"
                                           viewerName="My Viewer"
                   ></v:reportPageViewer>
    In the backing bean, this is the relevant code:
        public Object getReportSource() throws ReportSDKException
            if (propertiesChanged || reportSource == null)
                propertiesChanged = false;
                if (reportLocation == null)
                    throw new RuntimeException("The reportLocation property must be set before a report source is retrieved");
                ReportClientDocument rcd = new ReportClientDocument();
                rcd.setReportAppServer(ReportClientDocument.inprocConnectionString);
                rcd.open(reportLocation, 0);
                DatabaseController dbc = rcd.getDatabaseController();
                //Create the POJO collection and populate it with data
                ReportData[] data =
                  new ReportData("B.B.", "King", 6, new Date(25, 9, 16)),
                    new ReportData("Muddy", "Waters", 7, new Date(15, 4, 4)),
                    new ReportData("John Lee", "Hooker", 8, new Date(16, 8, 16)),
                    new ReportData("Otis", "Rush", 9, new Date(34, 4, 29)),
                    new ReportData("Buddy", "Guy", 10, new Date(36, 7, 30))
                //Create the result set from the collection of POJOs
                POJOResultSetFactory factory = new POJOResultSetFactory(ReportData.class);
                factory.setVerbose(true);
                POJOResultSet results = factory.createResultSet(data);
                ResultSetMetaData metaData = results.getMetaData();
                //Set the resultset as the report datasource
                      //Get the table name from the 'Set Datasource Location' dialog in the Crystal Reports designer
                String reportTable = "getReportDataDataSource";
                dbc.setDataSource(results, reportTable, reportTable);       
                IReportSource reportSource = rcd.getReportSource();
                if (reportSource == null)
                    throw new RuntimeException("Unable to get a report source.");
            return reportSource;
    In the CRConfig.xml, this is what is there:
    <?xml version="1.0" encoding="utf-8"?>
    <CrystalReportEngine-configuration>
        <reportlocation>../reports</reportlocation>
        <timeout>0</timeout>
        <ExternalFunctionLibraryClassNames>
             <classname></classname>
        </ExternalFunctionLibraryClassNames>
    </CrystalReportEngine-configuration>
    The report template 'Report1.rpt' is packaged under WEB-INF/reports in the war file.
    When I try to generate the report by accessing the JSF page, I am getting an error: "The report source could not be retrieved from the state object. "
    I am not sure what is wrong. Can someone help me in resolving this issue?
    Edited by: renshai on Jul 9, 2009 3:21 AM

    My formatting gets lost and the message looks unintelligible. After some experimentation, I found that if the message exceeds some length, the formatting is removed. Since I couldn't find any way to delete this post, I made another post with the same subject. Please ignore this post and help me to find a solution for the problem posted in the other thread with the same subject. Thanks in advance.

  • When will the demo object be eleigible for garbage collection?

    class Test {
         private Demo d;
         void start() {
         d = new Demo();
         this.takeDemo(d);
         void takeDemo(Demo demo) {
         demo = null;
         demo = new Demo();
         }

    Hey flounder, I am myself confused about garbage collection and assertions (yesterday)... Anyway because of ur interest in answering my query, I'll give one more try... But, if it's wrong, Please help me out.
    The Demo (not demo) object created at line 4 has one 'this' reference on the next line. And as soon as this reference is eleigible, I guess even Demo d will be eligible. Correct?

  • Closing the Statement returned from ResultSet.getStatement does not work

    With the ORACLE JDBC driver, I have discovered (the hard way) that it is essential to explictly close a Statement object after use. (http://www.orafaq.com/node/758 was useful here).
    Failure to do so leaves the Cursor open and eventually your application will fail with the ORA-01000 Too Many Cursors error.
    That works well if your code still has access to the Statement object which it created when it has finished with the results from executing the Statement.
    But, I've inherited some code where this is not the case. The results in the form of a ResultSet are passed through a few layers before it is eventually processed and can then be closed. The original Statement object is no longer available.
    I thought then that the solution would be use the ResultSet.getStatement method and to close that Statement.
    BUT that doesn't seem to work. The number of cursors continues to go up.
    Any ideas, anyone?
    (I'm using ojdbc6.jar and ORACLE 10g Express.)
    Edited by: Termind on 22-Jul-2010 10:00

    Copied in second message as first gets unreadable...
    eclipse.buildId=I20070625-1500
    java.version=1.5.0_18
    java.vendor=Sun Microsystems Inc.
    BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=de_DE
    Command-line arguments:  -os win32 -ws win32 -arch x86 -data D:\Dokumente\Projekte\workspace
    Error
    Tue Sep 29 11:30:49 CEST 2009
    Unhandled event loop exception
    java.lang.NullPointerException
    at org.eclipse.jpt.db.internal.ForeignKey.getReferencedTable(ForeignKey.java:104)
    at org.eclipse.jpt.gen.internal.GenTable.addReferencedTablesTo(GenTable.java:106)
    at org.eclipse.jpt.gen.internal.GenScope.buildReferencedTables(GenScope.java:169)
    at org.eclipse.jpt.gen.internal.GenScope.configureManyToManyRelations(GenScope.java:81)
    at org.eclipse.jpt.gen.internal.GenScope.initialize(GenScope.java:46)
    at org.eclipse.jpt.gen.internal.GenScope.<init>(GenScope.java:33)
    at org.eclipse.jpt.gen.internal.PackageGenerator.<init>(PackageGenerator.java:48)
    at org.eclipse.jpt.gen.internal.PackageGenerator.generateEntities(PackageGenerator.java:38)
    at org.eclipse.jpt.ui.internal.generic.EntitiesGenerator$GenerateEntitiesRunnable.run(EntitiesGenerator.java:129)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1797)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1779)

  • Can't Create Statement Object - Help

    Hi:
    I'm using NetBeans 5.0
    which is pointing at:
    Java\jdk1.5.0_07
    The IDE can't see the Statement object:
    'cannot find symbol Statement'.
    It won't compile.
    I've included: import java.* at the top of the file.
    It's not having a problem creating the connection object, just the Statement object.
    Can you tell me what I'm missing or what I need to make the IDE 'see' the Statement type?
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    oCn = java.sql.DriverManager.getConnection(getConnectionUrl), userName,password);
    Statement stmt = oCn.createStatement(); //<<-- IDE cant' see this

    Never mind. I figured it out:
    import java.sql.
    In general, these forums are GREAT!!
    Thanks very much for all the answers you 've given me.
    You're better than ANY support team:o)

  • How to highlight State of Multi-State object?

    hi,
    I have created 3 states of object State1, State2, State 3. and want to highlight state in object state panel programmatically. can any one have idea abt it?

    @Priyanka – you did not mention a specific scripting language.
    In ExtendScript (JavaScript) you can set the "active" property of the 3rd state of your MultiStateObject to value "true".
    //ExtendScript (JavaScript) example
    //Make sure a MultiStateObject is selected; nothing else, then run this JavaScript:
    app.selection[0].states[2].active = true;
    The expression from left to wright (for lurkers who never saw a line of code):
    app => application (that's InDesign, of course)
    selection => your current selection in the UI (could be one item, could be many)
    [0] => index number 0 is the first item in your selection; be cautious with the expression "first", it depends on the InDesign version what that does exactly mean, if you selected more than one object
    states => obviously the "state" object (always with the plural "s", it's the collection of all states in that selected MultiStateObject)
    [2] => index number 2 is the 3rd element of the states collection
    active => property for the active status; boolean, could be "true" or "false"
    = => with the "=" sign, you are setting the value
    true => the value of the property; self-explanatory, I hope…
    ; => end of expression, all that comes after is a different expression.
    The different parts are held together with a dot-notation. The index  is directly glued to its object, no dot notation between object and index.
    If you want learn more about ExtendScript and the InDesign DOM see Jongwares' documentation at:
    http://www.jongware.com/idjshelp.html
    Uwe

  • Save the state of the bean within the bean

    If i have a bean say BigBean which contains another bean say SmallBean.
    Both of SmallBean and BigBean implment seriablizable. If i save the BigBean, will the state of the SamllBean be saved automatically ?

    Yes.. if your SmallBean field is non-transient.

  • 10g: Initialize State object?

    I like the idea of using the State object on the Page to manage State. I've coded the EventHandler to read the parameters and store them on the state, and I see how to read them back from the state when re-rendering the page. My object model also knows what the default selections should be when the user first opens the page, but I don't know how to get these into the State before the user makes their first set of selections and submits those to the EventHandler.
    This seems to be related to the suggestion in the documentation that one "should always gracefully handle the absence of a State object." I'd rather not have to code the equivalent of "selectedValue = (uix:pageState == null ? getDefault : uix:pageState.selectedValue)" throughout the forms. What would be the most elegant way to put "if uix:pageState == null then pageState = getDefaultState" in the page? I was thinking about just creating a defaultState property on my dataSource and using that.
    Am I barking up the wrong tree? Are there recommended patterns to "gracefully handle the absence of a State object"?

    I'll ask around tomorrow.

  • "Setup encountered a problem while validating the state of Active Directory: Exchange organization-level objects have not been created, and setup cannot create them because the local computer is not in the same domain and site as the schema master. Run se

    Team,
    I am trying to Install Exchange on my Lab, getting below error
    message.
    The Schema Role is installed on Root Domain and trying to install
    exchange on Child domain.
    1 Root Domain - 1 Child domain. both are located on single site.
    “Setup encountered a problem while validating
    the state of Active Directory: Exchange organization-level objects have not been created, and setup cannot create them because the local computer is not in the same domain and site as the schema master. Run setup with the /prepareAD parameter and wait for
    replication to complete.”
    Followed below articles:
    http://support.risualblogs.com/blog/2012/02/21/exchange-2010-sp2-upgrade-issue-exchange-organization-level-objects-have-not-been-created-and-setup-cannot-create-them-because-the-local-computer-is-not-in-the-same-domain-and-site-as-the-sche/
    http://www.petenetlive.com/KB/Article/0000793.htm
    transferred the schema roles to different server on root domain, still no luck.
    can someone please help me.
    regards
    Srinivasa k
    Srinivasa K

    Hi Srinivasa,
    I guess, you didn't completed the initial setup schemaprep and adprep before starting the installation. You can do it as follows:
    1. Open command Prompt as administrator and browse to the root of installation cd and run Setup.exe /PrepareSchema /IAcceptExchangeServerLicenseTerms
    After finishing this,
    2. Setup.exe /PrepareAD /OrganizationName:"<organization name>" /IAcceptExchangeServerLicenseTerms
    3. To prepare all domains within the forest run Setup.exe /PrepareAllDomains /IAcceptExchangeServerLicenseTerms. If you want to prepare a specific domain run Setup.exe /PrepareDomain:<FQDN of the domain you want to prepare> /IAcceptExchangeServerLicenseTerms
    4. Once you complete all of the 3 steps, install the pre-requisities for Exchange 2013
    5. Finally, run the setup program
    Hope this will help you
    Regards from Visit ExchangeOnline |
    Visit WindowsAdmin

  • Can I change the state of an object by highlighting over text?

    That question probably doesn't make sense, but I didn't know how to word it with just a few words.
    I'm working on a site where I have a 'button' that has text in it. When someone hovers over the button, it changes colors (it's basically showing the user that the site is responding). When I put text inside the button, it causes the button to not change colors when I hover over it.
    I know that it's happening because the text is covering up the area that is supposed to respond to the user's mouse.
    So, I'm wondering if there is a way of either making the text and the 'button' all one object, or if it's possible to make the text 'invisible' to the mouse. What I mean by 'invisible' is that the computer wont acknowledge the text which will make the button responsive to the user's mouse.
    I am able to do this through photoshop but I was just wondering if it's possible to do this in only muse.

    Hi
    You can define states for the background layer such as rectangle and then insert text frame which will change the state on hover of mouse, but if the text frame covers the background then it wont active the state.
    The purpose that you are trying to achieve such as invisible text to mouse is not possible with native menu features , but yes as you have mentioned you can use an image for this , write up the text and use the image.
    The state button has same feature with rectangle in background and text within that.
    Thanks,
    Sanjit

  • Handle to error object after calling the statement execute - SQLDBC

    Topic related to SQLDBC inteface to MaxDB
    =======================
    In C++ while i was executing the statement
    rc = stmt->execute("SELECT 'Hello SAPDB' from DUAL");
    i could get a handle to the error object by a call to
    stmt->error().getErrorText()
    Now while using SQLDBC_C i am using
    rc = SQLDBC_Statement_execute(stmt,tempstr,strlen(tempstr),encodAsciiType);
    Now how do i get the handle to the error object ??
    Call like the above one
    fprintf(stderr, "Executed SQLDBC_Statement %s",stmt->error().getErrorText());
    gives me compilation error:
    error: invalid use of undefined type `struct SQLDBC_Statement'
    /opt/sdb/programs/sdk/sqldbc/incl/SQLDBC_C.h:125: error: forward declaration of `struct SQLDBC_Statement'
    Please Help and feel free to ask me if the question is not clear.
    Regards
    Raja

    Sorry. This question doesn't make sense. So, i withdraw the question.
    Basically what I had confused with earlier and got clarified now is:
    Just like when we make a call to SQLDBC_Connection_connect and after that use the SQLDBC_Connection_getError to get a handle to the SQLDBC_ErrorHndl.
    I wanted to know how should we get a handle to the SQLDBC_ErrorHndl after we have made a call to the SQLDBC_Statement_<function call>.
    I got the answer after looking through the SQLDBC_C.h file. It will be SQLDBC_Statement_getError and similarly SQLDBC_PreparedStatement_getError.
    Wish i could award myself the 10 points for solving the problem
    Regards
    Raja

  • Saving the state of an application - db, file, object?

    Hi, this is a general programming question,
    I don't understand when to use databases, files or just save objects to save a state of an application. If you can point me to a tutorial, that would be very helpful. Here I have specified my problem.
    I am creating a personal finance application. I am planning to have a month-object, which saves all my transactions for the month.
    I could create a database for all the transactions, and I guess it would be quite easy to get all the data from the database so that every time I start my application I would see my current financial situation.
    My questions is if there are other options for this.
    1. Writing to a file
    - What kind of a file can I write? Is it my own xml-style text-file from which I have to search for every data by an algorithm I have created myself?
    2. Objects.
    - I know I can save the state of an object to a file, which doesn't seem too complicated. When should I use this option.
    Thank you for any help on this question.

    I don't understand when to use databases, files or just save objects to save a state of an application. If you can point me to a tutorial, that would be very helpful.I doubt there's a good tutorial covering that, though I'd be delighted to be proven wrong.
    Here I have specified my problem.Excellent. This is what's known as "asking the right questions" :-)The XMLEncoder and XMLDecoder classes can be used to translate objects to and from XML files.
    The ObjectOutputStream and ObjectInputStream classes can be used to translate objects into and out of binary files.
    You could also, naturally, create your own file format(s) and translators.
    Finally you can use a database. You could use JDBC directly, or you could use one of the Object Relational Mapping (ORM) tools instead.
    Which to use?
    If you want to keep it simple go for the XML encoders. They're easy to use and you can read the file format.
    If you think you're likely to want to perform some complicated operations on the data, and particularly if you anticipate accumulating more data than will conveniently fit in memory at the same time, then consider using a database.
    You shouldn't use an ORM tool until you're very confident with JDBC so I'd rule that out for now.
    Given that you're asking this question at all, I would suggest the XML encoders for now.
    Thanks for asking the right sort of question - too many users pick a technology then demand that we help them use it without ever considering if it's actually appropriate. You're being smart. Well done.

  • I am new to Mac Pro but am purchasing one online.  can anyone tell me how to get the information from my Toshiba onto the Mac.  there are no stores in the state I live in.  Do I need to find a location and will they do a transfer from my I Tunes etc?

    I am new to Mac Pro and am purchasing one online  tonight.  Can anyone tell me how to get my information - Itunes, photos, and videos transferred onto the Mac from my Toshiba.  the state I live in doesn't have an Apple store but I could take it to Minneapolis when I go.  Any ideas where to begin?

    You might profit from a visit to a Minneapolis Apple store. With a brand new Mac, I think they will be most helpful - not just with transferring files, but with other advice as well. And I strongly recommend you invest in a back up drive. The Apple folk can help with that as well.

  • HT3529 I am currently deployed and was using my iMessage to be able to talk to family back in the states and my iMessage stopped working. It will no longer select my number to use as the send/receive. How do I fix this so I can continue to talk to family?

    I am currently deployed and was using my iMessage to be able to talk to family back in the states and my iMessage stopped working. It will no longer select my number to use as the send/receive. How do I fix this so I can continue to talk to family?

    Read here:
    http://support.apple.com/kb/TS2755

  • Ok, so basically my charger fell apart on my MacBook pro(2010) and I didn't have the money for a new charger, I got it in the states too if that's relevant. Basically my laptop will not charge, I bought a new charger yesterday and it's still no-use

    Ok, so basically my charger fell apart on my MacBook pro(2010) and I didn't have the money for a new charger, I got it in the states too if that's relevant. Basically my laptop will not charge, I bought a new charger yesterday and it's still no-use,not charging . No green or orange light coming on on the new charger either.

    It is one of the items that Apple gets criticized at regular intervals. The MagSafe connector is proprietary and unlicensable, so the company has a lock-in on the power options. And as you have now found out, your hijinks trying to avoid buying an expensive new charger may have caused more damage and led to a total no-charge condition.
    If lucky and no physical damage has occurred (there IS a fuse in there somewhere on the circuit boards), maybe resetting the SMC can restore charge functionality, provided there is still enough juice: http://support.apple.com/kb/HT3964

Maybe you are looking for