Where should i include my conn.close() command

Hi,
My code frequently fetches data from database, so i created a class like this
public class ConnectToDatabase { /*            public ConnectToDatabase()                 {                                 Connection conn;                 } */ public ResultSet selectS(String userQuery) throws Exception { String userName = "root"; String userPassword = "gal"; String databaseUrl = "jdbc:mysql://localhost:3306/test"; Class.forName ("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection (databaseUrl, userName, userPassword); String query = userQuery; Statement S=conn.createStatement(); ResultSet RS=S.executeQuery(query);                                 //conn.close;    ( "a" ) return RS;                                 //conn.close;    (" b ") } /*              public void closeConnection()                 {                                 conn.close;                 } */ }
and from the main code i make call as given below (it works fine)
ConnectToDatabase CTD=new ConnectToDatabase(); ResultSet result=CTD.selectS(String userQuery); //CTD.closeConnection();
Now my problem is
1) If try to give "conn.close()" before "return RS;"(marked by "a") It will show error (RS cannot be fetched after closing connectio)
2) If write conn.close after return it wont be executed (ofcourse - unreachable statement) ( "b" )
3) If use "CTD.closeConnection();" it gives errror saying that "cannot find conn(in closeConnection()) " i dont know why constructor is not loaded.(rest of commented lines when uncommented)
Where should i use conn.close statement? I dont want any change in my return type or parameters...

I used like this
public class ConnectToDatabase
   Connection conn;
   public ResultSet selectS(String userQuery,String[] userInput,int inputNumber )
       //code to select
   public void closeC()
       conn.close();
}and from main class
ConncetToDatabase CTD=new ConnectToDatabase();
ResultSet RS=CTD.selectS(x,y,z) ;
CTD.closeC();

Similar Messages

  • Where should i include the copied  payment advice script ?

    Hi experts,
    i  copied script from std script form (F110_IN_AVIS) . I did some modifications ,now i want to include this script name
    (my form name is YPM_F110_IN_AVIS)
    in the program.Where should i include (in f110 or somewhere) my script so that when executing the tcode FCH7
    modified script will be executed.please give me the steps.pls help me in this.

    you got this answer earlier today in another thread of yours....
    TA is FBZP.
    [url]find the payment advice script form name in fch7[url]
    Edited by: Florian Kemmer on Apr 15, 2010 1:20 PM

  • OnLoad - javascript - where should I include the code?

    Hi, have searched the forum and found that the pleace to include onLoad call should be included in the HTML Body section but when I try to apply the changes I get the error message:
    1 error has occurred
    * You may not declaratively set cursor focus if you specify an ONLOAD in this attribute. You can programatically set cursor focus by using the following syntax:
    onload="mystuff(); first_field();"
    my call is:
    onload="alert('test')";
    Thanks

    Hi,
    Have a look at the Edit Page Attributes for your page. On there is a Cursor Focus setting - make sure this is set to "Do not focus cursor". You can only have one onload for the body tag, so you can't have your javascript and this set to "First item on page"
    Andy

  • Where should RequestDispatcher.include() be used ?

    Hello again,
    I could not get the expected result from RequestDispatcher.include().
    First, I cannot use it to include static content; second, it does not include the dynamic contents in proper order.
    Now my question is, where can I use RequestDispatcher.include(), or should I use it at all ?
    The following are the source files and result on SunOne WebServer6.1 and Tomcat 5.5.12.
    IncludeDynamic.jsp
    <%@ page import="javax.servlet.RequestDispatcher" %>
    <html>
    <body>
         <h1>First partition</h1>
         <hr />
         <h2>
    <%
         RequestDispatcher rd = application.getRequestDispatcher("/jsp/IncludeHidden.jsp");
         rd.include(request, response);
    %>
         </h2>
    </body>
    </html>
    IncludeHidden.jsp
    Dynamic Inlcude Content
    The following is the HTML I get from the browser,
    Dynamic Inlcude Content
    <html>
    <body>
         <h1>First partition</h1>
         <hr />
         <h2>
         </h2>
    </body>
    </html>
    ----------------------------------------------------------------------------------------

    Try using
    <%@ include file="/jsp/IncludeHidden.jsp" %>
    instead of
    <% RequestDispatcher rd = application.getRequestDispatcher("/jsp/IncludeHidden.jsp"); rd.include(request, response); %>

  • How do I add a close command to multiscreen layouts?

    I need to add a close command multiscreen HTML5 screen layouts that will work on multiple platforms and browsers. I have 3 screen layouts defined: Desktop, Tablet, Mobile. These are called by a responsive design web application and display based on the screen width of the platform calling the help. My problem is that there is a requirement to be able to close the help. To do this I have added the javascript code:
    </a>
           <a href="javascript:window.close()" class="wPrintButton"><img
           src="Close.png" alt="" class="wPrintButton" border="0" />
    in each of the layouts to allow the user to close the help browser tab/window.
    My Desktop layout is based on the stock desktop. I added this command Topic.slp and SearchResults.slp d just to the right of the Print icon.
    My Mobile lay out is based on the stock iPhone. I added this as an additional row in the homepage links to the Home.slp.
    My Tablet layout is based on the stock iPad. Again I added this as an additional item to the homepage links to the Home.slp.
    My problem is - it appears that the window.close() javascript will not work with iOS. Has anyone incountered a similar problem and how did you deal with it?

    I had another idea that I am pursuing. I am looking into extending the current renderer CommandNavigationRenderer and will render another goLink just after the current goLink that will execute a close action. I was able to re-direct the rendering by added an override render-kit block in my current faces-config.xml file.
    <render-kit>
    <renderer>
    <component-family>org.apache.myfaces.trinidad.Command</component-family>
    <renderer-type>oracle.adf.rich.NavigationItem</renderer-type>
    <renderer-class>com.riscs.ui.backing.jsp.components.ClosableCommandNavigationItemRenderer</renderer-class>
    </renderer>
    </render-kit>
    If this works I am planning on extending the commandNavigationItem by creating a ClosableCommandNavigation tag and add a "closeAction" tag that will determine if a close item should render.
    Preliminary work looks promising. I will update if I make progress...please let me know if I am crazy.
    Thanks.

  • Difference between conn.close() and conn=null;

    Hi All,
    Can anybody please let me know the difference between conn.close()
    and conn=null;
    where conn is reference to Connection.
    Thanks and Regards
    -sunjavadeveloper

    Thanks for your response.
    Is there any other good approach to close() & then
    null the Obj. can u give us your opinion.
              finally
                try{
                         if(dbconn != null)     dbconn.close();
                         if(stmt != null) stmt.close();
                         if(rs != null) rs.close();
                         if(con != null) con.close();
                catch (Exception e)
                       logger.fatal(e.getMessage(),e);
    throw new Exception ("Exception -- Vendor.java --
    a -- authenticate -- " + e.getMessage() );
                   dbconn = null;
                   rs = null;
                   stmt=null;
                   con = null;
    Putting the close() calls in finally block is good, but having them in individual try/catch blocks is better. That way you can still try to close the connection if closing the statement throws an exception.
    I don't bother setting them to null. GC is smart enough to know that they've gone out of scope. I don't think it helps.
    %

  • Connection remains opened even after calling conn.close

    i have a need to copy records from one table in a database (say db1) to another table in another database(say db2). I open connection to both databases, and get a Recordset (say rs1) by executing a query that contains all rows that i have to insert in the database db2. Next i get an empty recordset(rs2) on the table in the database db2 (with locktype batchoptimistic, clientside cursor). i loop on rs1 and for each row in rs1 i insert a row in rs2 and copy the fields. after all rows are done, i delete the rows from db2 that will be affected and do an updatebatch on rs2. then i close the recordsets and the connections
    everything works fine except that the connection with the db2 is not getting closed, neither is it throwing any exception. when i comment the updateBatch code the connection closes normally.
    can anyone please help me out, where am i going wrong.
    thanks
    Vijay Sharma

    Hi,
    There is one more thing that I want to add to the above question. After calling conn.close() I checked the status of the connection and it was not 'OPEN' but when I checked session information through DBA studio it was showing one connection. I enabled trace of Oracle provider for OLE DB. Trace showed that two sessions were opened but only one session was closed.
    Thanks,
    Vijay

  • Where should i visit to get my photos in icloud storage

    where should i visit to get my photos in icloud storage and how can i sync all my camera roll on icloud as backup effectively.

    how can i sync all my camera roll on icloud as backup effectively.
    Backups of your iOS devices will include the Camera Roll: To backup your iOS devices see:
    For backing up to iCloud:   iCloud: Backup and restore overview  http://support.apple.com/kb/PH12519
    For backing up using iTunes:  iTunes: About iOS backups  http://support.apple.com/kb/HT4946
    where should i visit to get my photos in icloud storage
    In addition to Gail's  advice:  Right now only shared photo streams,  journals, and slideshows can be stored in iCloud and published on the web, so you can see them from other devices. But these photos will have a reduced resolution and will not suffice as a backup. These options are only for sharing.
    see this chapter in the iPhoto help on how to share your photos on the web:  http://help.apple.com/iphoto/iphone/2.0/?handbuch#blnk7d8f763e
    publish your journal
    photos as a slideshow
    iCloud Photo Sharing overview

  • Where Should I add the path of Down loaded librearys before working on form

    Hi all,
    This is Narendra.
    I am working on oracle apps technical.
    I have been working on reports,have little Knowledge on forms.
    After Instaliation before working on forms we have to down load librearys in to local mechian and add that path at some where.
    1)where should I add That path?
    2)From where I have to add down load that librearys?
    Regards,
    Narendra.
    [email protected]

    Narendra,
    If you want to open an Oracle Apps form using Forms Builder, then please do the following:
    - Copy all pll files, TEMPLATE.fmb & APPSTAND.fmb from $AU_TOP/resource to your local pc (C:\ABC)
    - Add (C:\ABC) to FORMS60_PATH in the registry (HKLM > Software > Oracle)
    - Close/Open Forms Builder
    - Open the form

  • Where Should I put the time capsule?

    Where Should I put the time capsule?
    I'm using a wireless modem/router provided by the internet company, and both (the TC and the router) are located next to the pc, in the living room . Using this way, I don't have signal in my bedroom. Should I get a signal amplifier?
    Thanks!

    It would be better to use EOP adapters (homeplug is another name) or ethernet to locate the TC closer to your room.. you can use another apple router to extend the wireless if you need to.

  • Can Acrobat XI be installed on a Windows PC where CS4 (which includes Acrobat Pro 9) is installed?

    Can Acrobat XI be installed on a Windows PC where CS4 (which includes Acrobat Pro 9) is installed?
    I have previously been told by Adobe tech support that the applications included in CS4 cannot be upgraded individually, and my guess would be that Acrobat XI and Acrobat Pro 9 cannot coexist on the same machine.  But I wanted to check and make sure.
    Doug Percival
    Technology Coordinator
    Center For Effective Government
    Washington DC
    <Removed by Moderator>

    they should be able to coexist.

  • How to identify the program in which an enhanncement spot should be included?

    How to identify the program in which an enhanncement spot should be included? For example I want to validate VA02 for USER authorization. So an enhancement spot should be written in program MV45AFZB. How do you identify this program ?

    It depends on where you need to place your modification, the enhancement will be assigned to main program,
    if you need to place in an include used by several program you need to make sure which main program is used by your transaction.
    In the case of MV45AFZB, the main program is SAPMV45A, but it's easy as this include is used only there,
    Max

  • Where should  file be placed  in real mobile in file browser application

    hello,
    i am doing an application on file browser i tested it in emulator it was having [b]appdbfolder bin folder tool kit which has the root directory with the file to be browsed
    1 but problem is where should i place the file in real phone
    2 if placed it resource dir it is not taking
    3

    just make sure your CLASSPATH includes cloudscape.jar. Not just the path, but also the jar filename.
    There is also a jre/lib/ext path in your java installation where you can dump your jar file so it will automatically be seen when you run your program.

  • Where should I place my preloaders?

    Hi all,
    Would like to seek advice on where should I place the
    preloaders.
    I have a banner swf, menu swf, main content swf, and intro
    swf. where should i load the preloader? on the main MC that will be
    calling these swf? or each swf have their own preloader? that would
    look rather weird.
    Of should I just merged banner, menu, main content and intro
    altogether? How do i do that? I am lost as to should I separate
    them out or put all eggs in 1 nest. My main content will have
    transitions between each sections.
    since my menu is separate from the main content, how do I
    point them to get the main content to change section whenever user
    click on 1 sections?
    I am so lost. Please advise. Thanks

    Hey X, sorry I haven't responded of late, working elsewhere.
    Let me address some of the questions you've had above.
    1) I'm very sorry, I see that I missed that assignment when I
    typed this out, within the loadFile function the correct call
    should be: mcl.loadClip(src, clip);
    2)the code is AS2, and yes it is legal coding. first, we're
    setting up parameters for our function here, and then we pass them
    this information when we call the method that we've set up, so that
    we can 'feed' information to the function that then uses it to
    perform it's job. the variable declarations in this case here are
    called 'strict typing' (ie. src:String, file:String, ...) and it's
    just a way to define variables of a particular 'type', it isn't
    necessary to follow the variable names with the type declaration,
    but I thought that I would include it here so that it made sense to
    you and so that you could see what type of variables need to be
    passed to the function. the varaibles MUST be passed to the
    function in the order that they are listed.
    3) yes you've got this all right :) The onLoadInit handler
    fires when the loaded clip becomes instantiated on the timeline
    (eg. available), previous to this point you could NOT say something
    like 'clip.gotoAndPlay(10);' because the loading clip was not yet
    available for the call, and it would fail. So you can use this
    handler to tell the loaded clip to 'do something' if you need this
    type of functionality, like say for instance that you need the
    loaded swf to go to a certain 'page' depending on what button the
    user pressed, this handler would be a way for you to pass that
    informtion along, and tell the loaded clip to goto the correct
    position, handy ;)
    As to the last question in 3, I touched on that above, my bad
    4) I was just talking about the name of the swf file being
    called 'dummy'.
    5) No, put everything in frame one, but on a different
    layers. Place your preloader on the top layer, and the 'blank' MCs
    (to load into) on layers below.
    OK, on to your last post.
    Yes, the way it's set up here the preload bar would run to
    100% for each load and then start again for the next one, it also
    has a text instance that tells the use what is being loaded each
    time. This could all be changed, and you can certainly use you own
    preloader instance, however you will need to reconstruct the method
    that is handling the progress. See if you wanted ALL of the
    instance your loading to equal 100% of your loader bars progress
    (for the first load anyway) you can't calculate the total bytes of
    all files previous to initiating the load, so you have a problem
    here. One method might be to 'break up' the load and apportion the
    progress indicator evenly for each item needed in the intital site
    loading. what I mean by that is, if you have 4 items that are
    needed to load, then each item would 'move' the progress bar by
    25%, so that when 100% of the first item is loaded, the progress
    bar is revealed by 25%, then the second load reveals 50%, and so
    on. It will just take a little math to change the code to handle
    the progressions. Now I would suggest that you NOT animate the
    masking rectangle by frames, I would do this with code adjusting
    the _x position of the mask by an amount that has been calculated
    with the loading code. also this method will have to accomidate,
    both multi-loads and singlular loads so you'll need to use another
    parameter to define how the preload indicator progress is 'broken'
    and into how many parts. This would end up in the math that defines
    the system that controls the indicator.
    OK this should be enough for you to think about for now
    :)

  • Where should I be saving my video clips?

    I have hundreds of video clips from my camcorder and iphone.
    I've compiled a few of them into short videos in imovie of around 200MB and play them back via itunes on apple TV (and ideally would also like to play them via my ipod).
    Where should I be storing the videos - presumably in imovie? I could also store them in iphoto (where they initially get downloaded to) or itunes.
    When I convert them to itunes, am I saving two 200MB versions - one in imovie and one in itunes?
    Thanks in advance

    Yes. Store everything. Hard drives are at 10 cents a gigabyte or less.
    You need an external drive that is formatted as Mac OS Extended (journaled). (also called HFS+ journaled). If your drive is a FAT32 drive, you can repartition/reformat using Disk Utility.
    All moves should be made from within iMovie. If you do not, your projects will not work.
    In iMovie, click VIEW/EVENTS BY DISK.
    You should see your disk drive listed in the Event Library List and the Project Library List. You can Command-Drag the small icons for the Events onto the small icon for the drive, and this will move them. (If you do not hold dowm the command key while dragging, it will copy, not move).
    You can do the same command-drag action in the Project Library List.
    A slick way to have a complete copy on external disk is to first command-drag the Project to the external disk (as mentioned above. Then, with this Project selected in the Project Library List, click FILE/CONSOLIDATE MEDIA... This will move all Events that are used in the Project to the same external disk. It will also put a copy of any photos or music used on the external disk, so you can take the external disk and edit on another Mac if you need to.

Maybe you are looking for

  • Can't get Macbook and Iphone to connect..Wrong Password?

    Ok, so I used the airport utility setup on my Imac and the connection works great. The airport is also sending out a full signal that both my iphone and macbook are picked up but says im unable to connect...grr, iv triple checked the password and eve

  • Error installing E-Bussiness Suite (EBS) R12 on Windows 2003 Server x32

    I am trying to install EBS R12 and i am getting error at stage 3 of 5 on 53% I followed steps from below link http://supportuae.wordpress.com/2013/01/26/installing-oracle-e-business-suite-r12-on-microsoft-windows-server-2003/ My Setup Win 2003 Server

  • PSD Import Issues

    I'm having trouble importing an 8-bit/RGB PSD file with 4 layers. One layer is a Smart Object, two are text layers, and the other is a standard image layer. When I tried to import this from the welcome screen using the default settings, Smart Object

  • Change value if array data is repeated

    Hello, I am trying to write a tuning algorithm that changes the calculated tune value after the program sees the same calculated value as before.  My tuning algorithm gets hung up on the extremes (5000 and 10000) and just goes back and forth and does

  • File saving settings. I want to save as ACM Waveform as a default

    I want my default save settings to be ACM Waveform, not Windows PCM. I have to load everything I create into a program called NexGen. It's a radio automation system. For some reason it's not taking the Windows PCM from Adobe 3. It was accepting the P