Problem : can't close a database connection

Hi,
I'am using connection pool under weblogic 6 and I can't close the connection when a SQL exception occures.
The connection always stay alive, even after a while, so when all connection have failed, I must restart the server.
Thanks for any kind of help.
Aurelien
Here my code :
public class MyDBClass {
     private ResultSet rs;
     private String query;
     private Connection conn;
     private PreparedStatement instruction;
     private WeblogicPool weblogicPool;
     public MyDBClass() {
     public boolean myDBMethod() {
          String data = ...
          long idTable = ...
          try {
               rs = null;
               instruction = null;
               weblogicPool = new WeblogicPool();
               conn = weblogicPool.getConn();
               query="insert into mytable (ID_TABLE, DATA) values (?,?)";
               instruction= conn.prepareStatement(query);
               instruction.setLong(1, idTable);
               instruction.setString(2, data);
               rs = instruction.executeQuery();
               rs.close();
               instruction.close();
               conn.close();
          catch (Exception e1) {
               e1.printStackTrace();
               try{
                    rs.close();
                    instruction.close();
                    conn.rollback();
                    conn.close();
               } catch (Exception e2){}
}The method getConn of WeblogicPool just returns a valid connection the the database

I've find an answer to my problem !
Statement (or PreparedStatement) and ResultSet objects must be declared into the try.
I don't know why it's working in this case ?!?
(Here, a best way to do the same as my first message)
public class MyDBClass {
     public MyDBClass() {
     public boolean myDBMethod() {
          Connection conn;
          WeblogicPool weblogicPool;
          String data = ...
          long idTable = ...
          try {
               weblogicPool = new WeblogicPool();
               conn = weblogicPool.getConn();
               PreparedStatement instruction = conn.prepareStatement("insert into mytable (ID_TABLE, DATA) values (?,?)");
               instruction.setLong(1, idTable);
               instruction.setString(2, data);
               ResultSet rs = instruction.executeQuery();
               rs.close();
               instruction.close();
               conn.close();
          catch (Exception e1) {
               e1.printStackTrace();
               try {
                    conn.rollback();
                    conn.close();
               } catch (Exception e2){}
          finally {
               if(con != null)
                    con.close();
}Thank's for your help !

Similar Messages

  • Can i use single database connection in a hole java application?

    can i use single database connection in a hole java application?.I have so many forms to use database connection.

    Theoretically you can. Not only theoretically. I've seen lots of application which only uses one database connection (they were using, oracle or mysql)
    The first reply given here assumed that the answer to
    your question depends only on the design of your
    application. That is not true.Yes it's true. Nothing in the original questions says that you aren't allowed to open or close the single connection that you have. It's looks more like the OP is interested in sharing a connection (i.e having a singleton or a connection pool with only one connection)
    It does also depend on the behaviour of the database
    in the background.
    Most databases have a time out for connections that
    are idle Not a problem. Most implementations of connection pools and applications which keeps a connection open have a timer which calls e.g. select * from dual (if you are using oracle) when the connection has been idle for X minutes.
    (some, like db2 on z/OS, even cancel
    connections, that are not idle, if they are open a
    certain amount of time or have reached a given limit
    of cpu seconds.)You would also have that problem if you had a connection pool with several connections.
    In essence: If you have no control over the time
    your application runs (and therefore your connection
    is open) or over type or the configuration of the
    database you are accessing, you can't do it.See above.
    The closest thing to what you want would be using
    PooledConnections, iif those are supported for the
    database you want to access.Not true.
    Kaj

  • How can I create a database connection to Cloudscape database in 9iJDeveloper?

    How can I create a database connection to Cloudscape database in
    9iJDeveloper?
    thanks.

    Hi,
    I assume you have a JDBC driver for Cloudscape.
    1. In the IDE System Navigator, expand the Connections Node.
    2. Right-click on the Database Connection and choose New
    Connection .. .
    3. Click pass the welcome screen.
    4. In Step 1, name your connection and choose "3rd party JDBC
    Driver"
    5. Follow the rest of the steps and provide username/password,
    class name and URL, test and you should be ready to go.
    Good luck.

  • I can't get a database connection.

    Background: I've already built two sites with databases using DW CS6, PHPMySQL, and the same hosting company, so I know they allow remote connections. (I'm developing using the remote host because I've never found a tutorial for how to move it all from local XAMPP to my host - but hey, it's been working fine so far.)
    I set up the database using CPanel Databases, added the user and password, no problem. Went into PHP MySQL and added a table, logged out and back in, the table is there as defined.
    In DW, I double-checked the testing server, tested the connection, and it connected successfully.
    Then I opened a page for editing and added a database connection (all as I had done on the previous two sites that work fine). I named the connection, entered the user, the password and tried to SELECT a database. No luck. HTTP Error 404. I manually added the database (the only one) and clicked test. Again no luck. HPPT Error 404.
    I double checked the testing server, double checked the DB information, and nothing seems to work.
    Any clue what I'm doing wrong? Thanks so much if you can help.

    UPDATE:
    Okay, this is really getting weird. As a typcial computer nerd, I know there are many roads to success, so if one doesn't work, try another.
    Trying a different solution, I opened a test.php page and wrote the following code:
    <?php
    echo "<p>Now testing database connection.</p>\n";
    $db_server = "localhost";
    $db_username = "mcsb831_mbradmin";
    $db_password = "***(redacted)***";
    $link = mysql_connect($db_server, $db_username, $db_password);
    if (!$link) {
        echo "Could NOT connect.<br />\n";
    }else{
        echo "Connected Successfully.<br />\n";
        mysql_close($link);
    I loaded the page to the server and guess what? I got the message "Connected Successfully."
    Hooray! Now I know the database server is running, and the database and user name and password are valid.
    I went to the DW MbrConnect01.php file (the name of the CONNECTION file that Dreamweaver creates when I tried to make the connection through DW), and verified the database name, user name, and password were correct -- I copied and pasted them from the code above to make absolutely certain there were no transcription errors. Here's that file:
    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_MbrConnec01 = "localhost";
    $database_MbrConnec01 = "mcsb831_members";
    $username_MbrConnec01 = "mcsb831_mbradmin";
    $password_MbrConnec01 = "***(redacted)***";
    $MbrConnec01 = mysql_pconnect($hostname_MbrConnec01, $username_MbrConnec01, $password_MbrConnec01) or trigger_error(mysql_error(),E_USER_ERROR);
    ?>
    And guess what?
    I GOT THE STINKING ERROR MESSAGE AGAIN!!
    (See previous post for the full text of the message.
    Yes, I checked the server using an FTP browser for the presence of the required files, and they are there.
    Does anyone have a clue what's going on here? I would absolutely love to use DW's DB automation tools, but none of them will work if I can't get a DW connection to work.
    I notice that my code uses mysql_connect while the DW-generated code uses mysql_pconnect (which is deprecated), could that be the culprit? How do I fix it if so?
    PLEASE, can someone help?

  • Installation problem with NW'04 SR1: database connection failed

    Hi all,
    while installing NW '04 SR1 on Windows Server 2003 SP1 and MS SQL Server 2000 SP4 I ran into an error related to the database connection. While performing the step "Load Java Database content" SAPinst crashes with the message
    com.sap.sql.log.OpenSQLException: Could not load class com.ddtek.jdbc.sqlserver.SQLServerDriver.
    The connection to the SLQ Server with e.g. the Query Analyzer is OK. I had a problem with this installation setup before (have a look at the corresponding <a href="https://forums.sdn.sap.com/thread.jspa?threadID=338638&tstart=0">thread</a> ), the JDBC drivers where missing on the installation master but after copying them in the right direction the installation went on with no problem up to this point...
    Has anybody an idea what could have happened here? Is this maybe a problem connected to the one I recently had
    Below I attached the sapinst.log and jload.log with more detailed messages.
    sapinst.log ###########
    INFO 2007-03-12 22:06:24
    Working directory changed to C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_~1\ONE_HOST.
    INFO 2007-03-12 22:06:24
    Output of D:\Java/bin/java.exe '-classpath' './sharedlib/antlr.jar;./sharedlib/exception.jar;./sharedlib/jddi.jar;./sharedlib/jload.jar;./sharedlib/logging.jar;./sharedlib/offlineconfiguration.jar;./sharedlib/opensqlsta.jar;./sharedlib/tc_sec_secstorefs.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\base.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\util.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\sqlserver.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\spy.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jce_export.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jsse.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_smime.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_ssl.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/w3c_http.jar' '-showversion' '-Xmx512m' 'com.sap.inst.jload.Jload' '-sec' 'WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key' '-dataDir' 'S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP' '-job' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML' '-log' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log' is written to the logfile C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_~1\ONE_HOST/jload.java.log.
    WARNING 2007-03-12 22:06:26
    Execution of the command "D:\Java/bin/java.exe '-classpath' './sharedlib/antlr.jar;./sharedlib/exception.jar;./sharedlib/jddi.jar;./sharedlib/jload.jar;./sharedlib/logging.jar;./sharedlib/offlineconfiguration.jar;./sharedlib/opensqlsta.jar;./sharedlib/tc_sec_secstorefs.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\base.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\util.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\sqlserver.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\spy.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jce_export.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jsse.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_smime.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_ssl.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/w3c_http.jar' '-showversion' '-Xmx512m' 'com.sap.inst.jload.Jload' '-sec' 'WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key' '-dataDir' 'S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP' '-job' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML' '-log' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log'" finished with return code 1. Output:
    java version "1.4.2_13"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_13-b06)
    Java HotSpot(TM) Client VM (build 1.4.2_13-b06, mixed mode)
    12.03.2007 22:06:25 com.sap.inst.jload.Jload main
    INFO: Jload -sec WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key -dataDir S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP -job C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML -log C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log
    12.03.2007 22:06:26 com.sap.inst.jload.Jload main
    SCHWERWIEGEND: couldn't connect to DB
    com.sap.sql.log.OpenSQLException: Could not load class com.ddtek.jdbc.sqlserver.SQLServerDriver.
    ERROR 2007-03-12 22:06:26
    CJS-20065  Execution of JLoad tool 'D:\Java/bin/java.exe '-classpath' './sharedlib/antlr.jar;./sharedlib/exception.jar;./sharedlib/jddi.jar;./sharedlib/jload.jar;./sharedlib/logging.jar;./sharedlib/offlineconfiguration.jar;./sharedlib/opensqlsta.jar;./sharedlib/tc_sec_secstorefs.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\base.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\util.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\sqlserver.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\spy.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jce_export.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jsse.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_smime.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_ssl.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/w3c_http.jar' '-showversion' '-Xmx512m' 'com.sap.inst.jload.Jload' '-sec' 'WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key' '-dataDir' 'S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP' '-job' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML' '-log' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log'' aborts with returncode 1. Check 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log' and 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.java.log' for more information.
    jload.log ###########
    12.03.07 22:06 com.sap.inst.jload.Jload main
    INFO: Jload -sec WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key -dataDir S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP -job C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML -log C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log
    12.03.07 22:06 com.sap.inst.jload.Jload main
    SEVERE: couldn't connect to DB
    com.sap.sql.log.OpenSQLException: Could not load class com.ddtek.jdbc.sqlserver.SQLServerDriver.
    Best regards,
    Bernd

    Hello Kairat,
    Please follow the below mentioned guide to install it.
    Check all the parameters to set and run pre requisite checker before starting installation.
    Keep in mind that before starting any SAP installation you should always run prerequisite checker.
    https://websmp205.sap-ag.de/instguides --> SAP Netweaver -->SAP Netweaver 7.0 -- > Installations --> EHP2
    Regards,
    Amit Barnawal

  • Xsql setup problem. 'Cannot acquire a database connection to process page.'

    This is probably a really basic problem, but I am getting the following error when I try to use the xsql demos.
    Oracle XDK Java 9.2.0.2.0 Production
    XSQL-007: Cannot acquire a database connection to process page.
    Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=150999297)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
    I really don't know what I am doing wrong, so any help would be appreciated.
    My jserv.properties file:
    wrapper.classpath=s:\xdk_java\lib\xsu12.jar
    wrapper.classpath=s:\xdk_java\lib\oraclexsql.jar
    wrapper.classpath=s:\orant\jdbc\lib\classes12.zip
    wrapper.classpath=s:\xdk_java\lib\xmlparserv2.jar
    wrapper.classpath=s:\orant\xdk\admin
    Thankyou
    Adrian

    hehehhe
    I had the connection wrong in the XSQLConfig.xml file.
    It's all working nicely now.
    Ade

  • Can i change the database connections through MAXL Scripts?

    Hi,
    just want to know whether i can change the database connections through MAXL Scripts. i am using essbase 9.3.1.

    Hi John,
    I have built my rulefile by connecting to a database & now i want to change the database connections. I know i can change the database connections through frontend. ( File--> open file). I want to know whether i can change the database connections by writing any MAXL Scripts.

  • Can't disconnect from database connection

    Hello,
    One of our application has been running for over a year on a client network, a windows desktop executable connected to an Oracle Standard One Edition, rel. 10.1.0.2., on a Linux server. Now the executable hangs when the users exit the app. It is build using Oracle Objects For OLE and the culprit is the close method of the ODatabase object. Strangely however, we found out that other applications can’t disconnect anymore:
    Both SQL*Plus and Toad will hang when exiting.
    Also, doing a connection test with the Net Manager hangs when a valid login is used. If I put an non-existing user or a locked one (scott/tiger for example), the server does report the problem.
    I've enabled local client tracing on a user desktop but there are no errors reported, which makes sense since it seems like nothing is coming back.
    The network admin over there swears nothing has change on the network config. So I’m hunting possible cause for this. There are several logs file cluttering up disk space in various folders and this file:
    /home/oracle/OraHome_1/sqlnet.log is now up to 3.1 Mb. I believe I can safely delete this one from other messages I found in various newsgroup. I would be surprise however that disk space is the problem since the windows app works fine, doing query in SQL*Plus works fine. (I only tried Toad to check the disconnect “feature”, not familiar with this tool, but it was showing the schema correctly)
    As a developper, I am however curious on whats happening when a disconnect is sent to the server and what are the expected responses, which don’t seem to be coming back anymore. It really looks like some packets are lost on their way back.
    Thanks in advance,
    Eric

    Many thanks! You hit the problem right on!
    Oddly, I can't even drop or disablee the trigger, SQL*Plus freeze. The network admin will perform a shutdown tonite when nobody is using the software. I'll see if I can drop it then.
    Regards,
    Eric

  • Can't create a database connection

    I've downloaded and installed a trial version of BusinessObjects Edge BI to see if my company should use it, but I'm having a problem figuring out how exactly to create a connection to a database.  I've used the Windows (I'm running Windows 7) ODBC tool to create a connection to a PostgreSQL 8.4 database server, and can use Excel and a trial of Crystal Reports 2011 to run queries against it, so I don't believe the problem is with the ODBC connection.  I've read as much as I could of the documentation and guides and tutorials on this site, and I'm pretty sure that I first need to create a universe in which I then create a connection to the database; I keep being referred to the Information Design Tool (IDT), but I can't seem to find it on my machine. So my questions are:
    1) Am I pointed in the correct direction, or do I need to be looking in a completely different place to create a connection?
    2) Is this Information Design Tool a desktop application? (if so, where should it have been installed?) or a webapp? (if so, what is the url?)
    3) Is this tool not included with the trial version of the software? (if so, is there a way to connect to a database with the trial version?)
    Any help at all would be most appreciated.  Thanks.

    Hi
    Could you please let me know if you have created that odbc connection for crystal report  in 32bit ODBC driver or 64 bit ODBC driver
    If your using 64bit odbc driver for that crystal report, then please change the ODBC driver connection to 32 bit ODBC driver and test the issue
    Regards,
    Raja

  • How can we close the TCP connection in Extend Clients (C#)

    I tried to use a C# client to connect to server side Coherence Nodes. The problem is that, Coherence creates two new TCP connections every time I create a new cache, and it never closes the connection. In the end, Coherence keeps opening hundreds connection for me, and I faced the Out Of Memory Exception.
    I used Coherence Extend for the connection, and use Thread.CurrentPrincipal. I did the same thing in Java, and it works. I don't know why it doesn't work for C#.
    For now, is there any way provided by Coherence to close the open TCP connection?

    The issue was the AZURE_STORAGE_CONNECTION_STRING was set improperly. I was originally using the value from the 'sig' querystring value, instead of the entire signature querystring.
    SET AZURE_STORAGE_CONNECTION_STRING=BlobEndpoint=https://viperprodstorage1.blob.core.windows.net/;SharedAccessSignature=<signature>
    Should have been...
    SET AZURE_STORAGE_CONNECTION_STRING=BlobEndpoint=https://viperprodstorage1.blob.core.windows.net/;SharedAccessSignature=sr=c&si=foobar-prod-policy&sig=<signature>
    After that was set, I was able to upload.
    I don't know if this mattered much, but I also changed the format of the call to...
    azure storage blob upload -f "file.gz" --container "foobar-prod" -b "file.gz" --verbose

  • Can EntityBean have two Database connection?

    assume:
    There is two database wihich has AAA table, and AAA table has same
    structure, so I want to use an EntityBean to use AAA table, then how can
    I program for this?

    Then how to tell the entity beans to choose which datasource to use during runtime?
    Let say i have 2 users. Each user maintains their own session.
    User A wants to access BMP AAA with datasource jdbc/dsA, but at the same time
    user B would like to acess the same BMP AAA but with datasource jdbc/dsB.
    Can BMP cater this? Thanks for your reply.

  • How can I kill database connections

    I would like to know how can I kill all the database connexion at the end of an application. I'm using acces
    thx

    use con.close() in a finally statement after your catch blocks that tests whether con equals null. If con != null, then con.close();
    example:
    finally {
              //close the database connection.
              try {
                      if (con != null) con.close();
              catch (SQLException e) {
    }

  • How can I get Connection(Database Connection)on my backing bean

    hello guys!
    How can I get the Database Connection on my managed bean?
    I want to use this connection for my reports.
    thanks a lot!
    alvin

    Alvin,
    You can access the data provider through ADF the binding. The data provider represents the business service you use. Once you have a handle to this you can get the connection.
    You don't mention the business service, so I cannot help you more than this. If it is ADF BC, have a look at http://download.oracle.com/docs/html/B25947_01/toc.htm and the stored procedure section. Steve Muench explains a trick to access the "real" JDBC connect used by ADF BC
    Frank

  • Database connection problem when i try store the values in JTable

    Hi Sir,
    I have a database connection problem when i try to store the data's in a JTable.I think the problem is with in the database connection.I have used 3 vectors here.The database which i have used is
    Access.Where the program is compiling well.But when i run it only the first column heading is printed and error message showing that
    "Invalid Cursor State".I need to solve this problem.pls. do help me.
    I will provide u with the code.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.sql.*;
    public class DataBaseVector extends JPanel
    //Container contentPane=getContentPane();
    JScrollBar jsb = new JScrollBar(JScrollBar.HORIZONTAL);
    JScrollBar jsb1 = new JScrollBar(JScrollBar.VERTICAL);
    Image i1;
    String url="jdbc:odbc:Ananth";
    Vector col=new Vector();
    Vector rows=new Vector();
    Vector rdata=new Vector();
    Connection conn;
    public DataBaseVector()
    //super("JTable With ScrollBars");
    this.setLayout(new BorderLayout());
    UIManager.put("ScrollBar.track",Color.red);
    UIManager.put("ScrollBar.thumb",Color.blue);
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn=DriverManager.getConnection(url); // Is there any problem here?
    Statement st=conn.createStatement();
    ResultSet rs=st.executeQuery("Select * from AccountMaster");
    // rs is the result set obtained
    ResultSetMetaData rsmd=rs.getMetaData();
    int cols=rsmd.getColumnCount();
    for(int i=1;i<=cols;i++)
    col.addElement(rsmd.getColumnName(i));
    rdata.addElement(rs.getString(i));
    rows.addElement(rdata);
    }catch(Exception e)
         System.out.println("The Error Message was:"+e.getMessage());
    JTable jt=new JTable(rows,col);
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp=new JScrollPane(jt,v,h);
    this.add(jsp,BorderLayout.CENTER);
    this.add(jsb, BorderLayout.SOUTH);
    this.add(jsb1, BorderLayout.EAST);
    public static void main(String args[])
    JFrame jf=new JFrame();
    JPanel frame=new DataBaseVector();
    jf.getContentPane().add(frame);
    jf.setSize(800,600);
    jf.setVisible(true);
    Thanx,
    m.ananthu

    The problem is ResultSet.next() is not called.
    Try this and modify the table creation as you need.
    ResultSetMetaData rsmd=rs.getMetaData();
    int cols=rsmd.getColumnCount();
         while(rs.next()) {
              for(int i=1;i<=cols;i++)
                        col.addElement(rsmd.getColumnName(i));
                        rdata.addElement(rs.getString(i));
              rows.addElement(rdata);
    Hope this helps

  • Database Connection Pattern

    Hi:
    I'm looking for a best practice to centralizing access to the database. All the examples that I have seen on the Sun site and the Internet look a little clumsy. What I'm trying to ask is this. Instead of CODING a connection object, Statment object etc. like the examples provide - every time I make a query. Is there a better way of centralizing make making this code generic.
    For example:
    I have an object that describes my records say ModelBunny
    mBunny.setEars
    mBunny.setTail
    mBunny.setColor
    I have an object that describes all my database queries that I want to execute say DataBunny
    dBunny.getBunnyByID
    dBunny.getAllBunnies
    dBunny.getBunnyByColor
    I created a transaction object that allows me to load up multiple sql commands into the transaction object for more complex calls.
    I pass the transaction object into a generic connection object that opens, runs the transaction and then closes. For inserts, updates and deletes this pattern works great - I pass back an array of int and let the user know what happened - success/failure.
    Here is the root of the issue:
    in my generic connection object - I create a query method. Where I pass in a single query statement that returns a - resultset (yes here is my problem).
    The resultset is only valid if the connection remains open - then as soon as I close out the connection in my "finally" - I'm done, toast, otherwise - screwed.
    I thought of making a method where I can manually close my connection from the calling object - but I want something more brainless where another developer using this framework won't forget and leave the connection dangling.
    Is there some way I can process the resultset generically into an arraylist and then pass back the arraylist?
    I'm not even certain that this pattern that I'm using is wise. Everybody seems keen on writing the same boiler plate code every time they want to execute a command. I don't think this is good design practice and make the code unmanageable. I'd like some advice or a pointer to something better.
    I'm using OracleXE for my test bed. I'd like to leave everything as generic as possible because our platform will likely shift to another DBMS.
    Thanks for your help.

    FYI: Here is the meat of the generic class that I'm talking about.
    public class DbConnection {
    private String _urlDbCnn       = "";   // the JDBC url to the database
    private String _username       = "";   // a valid username to access the database
    private String _password       = "";   // a valid password to access the database
    private String _dbDriver       = "";   // a valid JDBC driver
    private Connection _cnn            = null; // this will be the active connection
    private String _sqlStatement   = null; // this will be the statement to execute against the database
    public DbConnection(){
    this("oracle.jdbc.OracleDriver",
    "jdbc:oracle:thin:@//192.168.15.200:1521/xe",
    "usernamehere",
    "passwordhere");
    } // constructor - nothing
    public DbConnection(String nwDbDriver, String nwDbURL,
    String nwDbUsername, String nwDbPassword){
    this.setDbDriver(nwDbDriver);
    this.setUrlDbCnn(nwDbURL);
    this.setUsername(nwDbUsername);
    this.setPassword(nwDbPassword);
    } // constructor - DbDriver, DbUrl, DbUser, DbPassword
    private void initializeConnection(){
    // try - get database driver
    try{
    DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
    // try - initialize the database connection
    try{
    this._cnn = DriverManager.getConnection(this._urlDbCnn,
    this._username,
    this._password);
    }catch(SQLException e){
    ErrorTrap trap = new ErrorTrap(ErrorTrapMessage.DataConnectionNotIntitialized, e);
    } // catch - try and initialize the database connection
    }catch(SQLException e){
    ErrorTrap trap = new ErrorTrap(ErrorTrapMessage.DataConnectionDriverFailedToLoad, e);
    } // catch - try and get database driver
    } // method - OpenConnection
    public ResultSet executeQuery(DbTransaction nwTransaction){
    ResultSet results = null; // batch results are returned as an array of integers
    // initialize the database connection
    initializeConnection();
    // try - access the database connection and execute a batch of statements
    try{
    // if - check that the connection is open
    if (this._cnn.isClosed()== false){
    // create a statement object from the connection
    Statement sqlQuery = this._cnn.createStatement();
    // if - check that there is at least one command present
    if (nwTransaction.size() >= 1 ){
    // execute the batch success/error results are returned as an int array
    results = sqlQuery.executeQuery(nwTransaction.get(0).getCommand());
    } // if - check that there is at least one command present
    } // if - check that the connection is open
    catch(SQLException e){
    ErrorTrap trap = new ErrorTrap(ErrorTrapMessage.DataSQLTransactionFailed, e);
    } // catch - SQL Query
    finally{
    // try - close database connection
    try{
    //if - check that the connection is open
    if(this._cnn.isClosed() == false){
    // close the database connection
    this._cnn.close();
    } //if - check that the connection is open
    }catch(SQLException e){
    ErrorTrap trap = new ErrorTrap(ErrorTrapMessage.DataConnectionNotOpen, e);
    } // catch - try and close database connection
    } // finally
    return results;
    } // method - executeQuery
    public int [] executeTransaction(DbTransaction nwTransaction){
    int [] results = null; // batch results are returned as an array of integers
    // initialize the database connection
    initializeConnection();
    // try - access the database connection and execute a batch of statements
    try{
    // if - check that the connection is open
    if (this._cnn.isClosed()== false){
    // create a statement object from the connection
    Statement batchStatement = this._cnn.createStatement();
    // for - loop through each command added to the transaction
    for(DbCommand command:nwTransaction){
    // add the sql command for batch execution
    batchStatement.addBatch(command.getCommand());
    } // for - loop through each command added to the transaction
    // execute the batch success/error results are returned as an int array
    results = batchStatement.executeBatch();
    } // if - check that the connection is open
    catch(SQLException e){
    ErrorTrap trap = new ErrorTrap(ErrorTrapMessage.DataSQLTransactionFailed, e);
    } // catch - SQL Query
    finally{
    // try - close database connection
    try{
    //if - check that the connection is open
    if(this._cnn.isClosed() == false){
    // close the database connection
    this._cnn.close();
    } //if - check that the connection is open
    }catch(SQLException e){
    ErrorTrap trap = new ErrorTrap(ErrorTrapMessage.DataConnectionNotOpen, e);
    } // catch - try and close database connection
    } // finally
    return results;
    } // method - executeCommands

Maybe you are looking for

  • Writing dynamic value to a text file in Openscript

    How to write the dynamic values which i captured in a variable into a text file in openscript ? I searched throughout the user guide and i don't find any option for that. Please help, thanks in advance..

  • Create multiple paged pdf, ran out of room?

    I'm trying to create a 19 page pdf in AI, but it will not let me. Is there some way to resize the canvas, or something? I need 19 letter sized pages but it won't let me create them. Thanks for any help

  • How do I get my iTunes to recognize my new iPhone?

    How do I get my iTunes to recognize my new iPhone?

  • How to use Vectors ?????????

    Hi guys, i am a newbie in java and about to die due to some stressful assignments. I am not asking u to help in assignment. Just please share some knowledges about vector. How to use it? so that i can use it in my assignment. Thank u . AND IN THIS CO

  • Need to display only leaf and not the node using tree table

    Hi, Am using Jdeveloper 11.1.2.0.0 . As per requirement , am having Department - Employee View wherein Department is the parent considered as node and Employee as a child which is considered as a leaf. Having dragged and dropped the DepartmentView as