Database Access delays-how to improve upon that?

Hi friends,
I have this simple class,which takes in query and returns the results.I don't know why the database access is so slow,and if i try to add my driver load statements into the constructor the java class starts throwing "null pointer exception"(Java Class code given below)..I don't know much about connection pool,can u just have a look at this simple class,and tell me if there's anything on which i can improve upon and where to add the(*.close() statements).The same query runs instantly if i make a php program.Urgent help needed...please help me guys.
public class getResultSet{  private Connection con = null;  private Statement st = null;  private String dsn = "jdbc    b2j:net:xxx";  private String uname = "xxx";  private String pwd = "xxx";  private String query = "";  ResultSet results;   public void ResultS()throws Exception{      try{          Class.forName("com.ibm.db2.jcc.DB2Driver");          con = DriverManager.getConnection(dsn, uname, pwd);          st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,                                   ResultSet.CONCUR_READ_ONLY);         }      catch (SQLException e) {          e.printStackTrace();          }     }     public ResultSet getResults(String query){            results = null;            try{               results = st.executeQuery(query);               }               catch(SQLException sqle){                 sqle.printStackTrace();               }            return results;     }   }

Some comments on the code
public class getResultSet{ // Class names should start with a capital letter and be nouns
private Connection con = null;
private Statement st = null; // Statements are transient and should probably not be a member variable
private String dsn = "jdbc    b2j:net:xxx";  // dsn, user, pass should be final
private String uname = "xxx"; 
private String pwd = "xxx"; 
private String query = "";  // Seems you're not using this
ResultSet results;   // This really shouldn't be declared here
public void ResultS()throws Exception{ // Method should start with a lower-case letter and be a verb/* The client code is supposed to call this, then the other method?
Very fragile. I'm guessing NullPointerExceptions occur if ResultS
is not called first. Have the other method call this one as necessary.
try{        
Class.forName("com.ibm.db2.jcc.DB2Driver");
con = DriverManager.getConnection(dsn, uname,
uname, pwd);
st =
st =
=
con.createStatementResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ultSet.CONCUR_READ_ONLY);
catch (SQLException e) {  
e.printStackTrace();
public ResultSet getResults(String query){      
results = null;
try{          
results = st.executeQuery(query);
catch(SQLException sqle){   
sqle.printStackTrace();
return results; // It's a bad idea to return ResultSets as that leaves resources open
} // Where's the cleanup? You're leaving ResultSet, Statement, Connection open
>It is probably slow because opening connections takes a long time. You may or may not need a connection pool depending on your app. Perhaps you can just open a connection at the beginning and leave it open until your app finishes. That should reduce the overhead and still be very simple.

Similar Messages

  • OAS 10.1.2.0.2 - How configure PHP with database access

    I Installed OAS 10.1.2.0.2 on SuSe 9.3.
    I put in $ORACLE_HOME/Apache/Apache/htdocs a php pages for test if this OAS versión supported php.
    The test is ok, this versión support PHP, but not are configured to PHP with database access.
    My question is: How I configure this OAS 10.1.2.0.2 to use PHP with database access?
    I need install all PHP although my php pages is running (without database access) ??? or I only need configure database access?

    How I compile my PHP with --with-oci8??                                                                                                                                                                                                                           

  • 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?

  • HT5925 I have an iCloud email on my iPhone that is now old as hacked and unused. I can't access anything as it asks for that account info and I don't remember the password etc. How do I delete it and replace it with my new iPad email? ! Help..

    I have an iCloud email and Yahoo email on my iPhone that is now old as hacked and unused. I can't access anything as it asks for that account info and I don't remember the password etc. How do I delete and replace it with my new iPad email? ! Help..

    Welcome to the Apple community.
    If you are unable to remember your password, security questions, don’t have access to your rescue address or are unable to reset your password for whatever reason, your only option is to contact AppleCare(or Apple ID Support), upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.

  • How to create a .mdf SQL Server database from a Data-Tier Application file that has data?

    This is a noob question, though I do use SQL Server databases all the time with Entity Framework when I code in C# using Visual Studio 2013.  The development environment is found below at [A].  I am trying to make a clone of a SQL Server 2008 R2
    database (.mdf)  that exists online.  I can read, connect and work with this database in Visual Studio 2013, but I wish to make a local copy of the database, as an .MDF file.  Somewhere in my notes I have a way of creating a local copy from
    an online database when using Visual Studio but I forgot how (it seems, reviewing my notes, that it deals with ADO.NET which is deprecated in Visual Studio 2013 these days, or so it seems).  So I'm looking for another way.  What I did was create
    (or export) a "Data-Tier Application File" from the online SQL Server database, with data, and it seems to have worked in that this Data-Tier Application file exists on my hard drive and seems to have data in it ("SQL Server Replication Snapshot"
    is the format it seems).  It contains skeleton code to create a database, but when I tried to execute it with SQL Server 2014 Management Studio, I got a bunch of errors.
    So my question is:
    1) Can I somehow create a .MDF SQL Server Database from an Data-Tier Application file that has data?  What tool do I use?  I saw this link, http://social.technet.microsoft.com/wiki/contents/articles/2639.how-to-use-data-tier-application-import-and-export-with-a-windows-azure-sql-database.aspx 
    and it relates to Azure, but is there a tool for C#Visual Studio 2013, standalone?
    2) If there's an easy way to create a .mdf SQL Server Database file from an online file, within SQL Server Management Studio?  I don't think so, since it would require Administrator permissions on the online server, which I don't have. I have permission
    to read, update, delete the online database file, but strangely not to download it (the service I use has a tool for backup, but not for download).
    3) same question as 2), but for Visual Studio 2013?  I don't think so, since I notice none of the templates even mentions ADO.NET anymore, but instead they go with Entity Framework.  Using EF I can of course do anything I want with the online database
    (CRUD), but it remains online.  Maybe there's a switch to make a local copy?  I guess I could write a short program to suck all the data out of the online database and put it into a new, duplicate database having the same tables, that I create on
    my localhost, but my question here is if there's an easier way than this, maybe a tool or command I can run from inside Visual Studio?
    Any advice on any of the above questions is appreciated.
    Thank you,
    Paul
    [A] Microsoft Visual Studio Professional 2013
    Version 12.0.21005.1 REL
    Microsoft .NET Framework
    Version 4.5.51641
    Microsoft Web Developer Tools 2013   2.0.40926.0
    SQL Server Data Tools   12.0.30919.1
    Microsoft SQL Server Data Tools
    Windows Azure Mobile Services Tools   1.0
    Windows Azure Mobile Services Tools

    Thanks but these links are too general to help.
    "2. what do you mean by online file?" - I mean the SQL Server database file is on a remote web server that I rent from, but I am not the administrator of.  I can access my database using SQL Server Authentication, but nothing more.
    Paul
    What do you mean by too general? It explains on how you can use data tier application to create and deploy databases
    May be this will help you to understand better
    http://www.databasejournal.com/features/mssql/article.php/3911041/Creating-Data-Tier-Applications--in-SQL-Server-2008-R2.htm
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Performance improving in database access

    in se30 how shd i c the table acess to  in the analysis.
    for a kna1 table i shd c the no of accesses.
    in 4.6c
    goto->objecthitlist->database table is not  active ...
    is there any other way ..
    how shd i confirm that performance is incresed after  modifying a code.

    the SE30 can not help you much with that problem (also the database display which appears ponyl if ou use 'no aggregation' )
    For details on database accesses you need to run the SQL Trace, the SQL Trace is in any system since a very long time.
    See my weblog for details:
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/cs/junior/search/wlg?id_user=46921
    Siegfried

  • I have a new IMAC 5k running Yosemite and when I log in I am asked a whole series of questions as to what keychain can access. How can I authorise all of these to be available upon login? Items concerned are such as "Talagent", "Messages agent" etc

    I have a new IMAC 5k running Yosemite and when I log in I am asked a whole series of questions as to what keychain can access. How can I authorise all of these to be available upon login? Items concerned are such as "Talagent", "Messages agent" etc

    Back up all data before proceeding.
    Launch the Keychain Access application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad and start typing the name.
    Select the login keychain from the list on the left side of the Keychain Access window. If your default keychain has a different name, select that.
    If the lock icon in the top left corner of the window shows that the keychain is locked, click to unlock it. You'll be prompted for the keychain password, which is the same as your login password, unless you've changed it.
    Right-click or control-click the login entry in the list. From the menu that pops up, select
              Change Settings for Keychain "login"
    In the sheet that opens, uncheck both boxes, if not already unchecked.
    From the menu bar, select
              Keychain Access ▹ Preferences... ▹ First Aid
    There are four checkboxes in the window that opens. Check all of them. if they're not already checked. Close the window.
    Select
              Keychain Access ▹ Keychain First Aid
    from the menu bar and repair the keychain. Quit Keychain Access.
    If you use iCloud Keychain, open the iCloud preference pane and uncheck the Keychain box. You'll be prompted to delete the local iCloud keychain. Confirm. Then re-check the box. Follow one of the procedures described in this support article to set up iCloud Keychain on an additional device.

  • OracleXe - how to create a database access descriptor (DAD)

    Hi folks,
    I am trying to figure out how to create a DAD (database access descriptor) so I can access my pl/sql server pages which are installed on my oracleXe database.
    I have searched the docs and this forum and OTN but haven't found any information on how to do this.

    You can use DBMS_EPG for that purpose. E.g.:
    DBMS_EPG.CREATE_DAD (
       dad_name  IN  VARCHAR2,
       path      IN  VARCHAR2 DEFAULT NULL);More about DBMS_EPG you can find here:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_epg.htm
    In XML DB HTTP Server a DAD is represented as a servlet.
    Regards!

  • How to improve the write performance of the database

    Our application is a write intense application, maybe will write 2M/second data to the database, how to improve the performance of the database? We mainly write to 5 tables of the database.
    Currently, the database get no response and the CPU is 100% used.
    How to tuning this? thanks in advance.

    Your post says more by what is not provided than by what is provided. The following is the minimum list of information needed to even begin to help you.
    1. What hardware (server, CPU, RAM, and NIC and HBA cards if any pointing to storage).
    2. Storage solution (DAS, iSCSCI, SAN, NAS). Provide manufacturer and model.
    3. If RAID which implementation of RAID and on how many disks.
    4. If NAS or SAN how is the read-write cache configured.
    5. What version of Oracle software ... all decimal points ... for example 11.1.0.6. If you are not fully patched then patch it and try again before asking for help.
    6. What, in addition to the Oracle database, is running on the server?
    2MB/sec. is very little. That is equivalent to inserting 500 VARCHAR2(4000)s. If I couldn't do 500 inserts per second on my laptop I'd trade it in.
    SQL> create table t (
      2  testcol varchar2(4000));
    Table created.
    SQL> set timing on
    SQL> BEGIN
      2    FOR i IN 1..500 LOOP
      3      INSERT INTO t SELECT RPAD('X', 3999, 'X') FROM dual;
      4    END LOOP;
      5  END;
      6  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.07
    SQL>Now what to do with the remaining 0.93 seconds. <g> And this was on a T61 Lenovo with a slow little 7500RPM drive and 4GB RAM running Oracle Database 11.2.0.1. But I will gladly repeat it using any currently supported version of the product.

  • How to improve database link performance?

    Hello all,
    We use db links to do DML operations on remote databases. For OLTP applications we are facing performance problems for transactions dependent on data on remote database.
    For legal and business reasons we cannot state all the data locally.
    Could anybody suggest how to improve database links performance or suggest methods/procedures/techniques to enhance speed of OLTP applications going against remote databases ?
    Thanks
    Sky

    AQ is as reliable as Oracle-- the guarantees about delivery of queued messages are the same as the guarantees about committed transactions (i.e. ACID). AQ is designed for asynchronous operation, though. If you are batching transactions, it sounds like you are already doing some sort of asynchronous operations-- I've generally found AQ a lot easier to administer & maintain than rolling your own batching system.
    If you want to tune the Oracle side of things, you'll need to explain more about the system(s) involved here. Architecture, data flow, operations that involve the dblink, etc. If you're not comfortable posting that sort of information to a public forum, feel free to send me mail directly [email protected]
    As an aside, I'm interested in how you can legally pull data from the remote system to display to your users but that you can't legally cache that data in your system via replication. Sounds like an odd constraint.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How can I access files from a flash drive that were previously saved using a Windows computer? When I attempt to open the file on MacBook Pro, it is asking to "convert file to"; I also have Microsoft Word installed on the Mac as well.

    How can I access files from a flash drive that were previously saved using a Windows computer? When I attempt to open the file on MacBook Pro, it is asking to "convert file to"; none of the options I choose work. I also have Microsoft Office (with Word) installed on the Mac as well.

    Format the external drive as FAT32 or ExFAT. Both computers will then be able to read and write to it.

  • I uploaded music to my MacBook and I went to open my iTunes account on another computer and could not access them. How do I do that?

    I uploaded music to my MacBook and I went to open my iTunes account on another computer and could not access them. How do I do that?

    Welcome to the Apple Community.
    The following article(s) may help you.
    Understanding Home Sharing
    Setting Up Home Sharing On A Computer

  • Hey, for some reason i turned on my macbook pro 2012 and it says i have no internet access. I then found out that it also says that my self assigned ip address will not connect to the internet. How is this and how can i fix it?

    hey, for some reason i turned on my macbook pro 2012 and it says i have no internet access. I then found out that it also says that my self assigned ip address will not connect to the internet. How is this and how can i fix it?

    Reset your modem.

  • I have an old Ipod 5th gen that I have been using for downloading music from my library.  Upon purchasing an Ipod touch and registering it in Itunes, I can no longer sync tunes to my old ipod.  How can I get that option back on my old ipod?

    I have an old Ipod 5th gen that I have been using for downloading music from my library.  Upon purchasing an Ipod touch and registering it in Itunes, I can no longer sync tunes to my old ipod.  How can I get that option back on my old ipod?

    - iTunes purchases by maybe
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer
    - For other music you need a third-party program like one of those discussed here:
    newer copy
    BTW, this is the iPod touch forum.

  • I can no longer view my photos through th photo icon.  There is not an icon on my "slide to unlock" screen that when touched starts a slide show of my photos.  How do I turn that off so I can access my photos as before?

    I can no longer view my photos through th photo icon.  There is not an icon on my "slide to unlock" screen that when touched starts a slide show of my photos.  How do I turn that off so I can access my photos as before?

    Oroilore-
    I do not see a way to disable the Picture Frame icon.  I looked at Settings-Picture Frame, but none of the options turns it off.  The only way I can thinik of, would be if all of your photos had been deleted.  If there were no photos, you couldn't have a slide show!
    One thing to try is to reset (reboot) your iPad.  Hold both the Home and Sleep buttons for several seconds until the Apple logo appears.  Ignore the "Slide to power off" arrow.  The iPad will restart after a couple of minutes.  Resetting this way will not hurt anything, and sometimes clears up mysterious problems.
    Fred

Maybe you are looking for

  • How to select a shape from pen tool for paint bucket

    I was under the notion that I could make a shape with the pen tool and if I closed the the shape it would then be selected in a way that would allow me to color the interior with paint bucket. However, when I splash the paintbucket inside my shape, i

  • PDF report font problem

    Dear all, All our reports are developed by reports builder 10g (under windows) and deployed on an Application Server 10g (on Linux). We had a problem with displaying the arabic letters, but this was solved by following the steps in the metalink doc n

  • When I try an install the GPIB drivers from the CD for NT I get an error. It says the GPIB software is not properly instal

    led. Please run the GPIB setup software from your disk. Once it is installed use ibconf to modify your settings. Under error information is says file: reginfo.c Line: 3601 and Item knownDLLs. Am I missing a file, what is reginfo.c, what is error 3601

  • Trouble loading a large number of csv files

    Hi All, I am having an issue loading a large number of csv files into my LabVIEW program. I have attached a png of the simplified code for the load sequence alone. What I want to do is load data from 5000 laser beam profiles, so 5000 csv files (68x68

  • How to update DBTABLOG?

    Does anyone know how to use a Z*-program to write entries to the database log table DBTABLOG?     The reason I'm asking is we have a batch job to update table T001b. Due to the Sabine-Oxlay requirements, I need to add entries to DBTABLOG each time th