Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:20:11+00:00 2026-05-25T14:20:11+00:00

I’m trying to execute 2nd time PreparedStatement , but it fails if I close

  • 0

I’m trying to execute 2nd time PreparedStatement, but it fails if I close DriverManager.getConnection

the code:

public void getRates(String id) throws Exception, DBException {

        Connection conn = null;
        ResultSet rs    = null;

        try {

            conn = getConnection();

            if (ratesQueryStmt == null){
                ratesQueryStmt = conn.prepareStatement(ratesQuery); 
            }
            ratesQueryStmt.setString(1, id);

            ratesQueryStmt.setQueryTimeout(m_nTimeout);

            rs = ratesQueryStmt.executeQuery();

            while (rs.next()){
                System.out.println("!!!\n\nDATE = " + rs.getString("RATE_DAY") + " PURCHASE_PRICE = " + rs.getString("PURCHASE_PRICE") + " SELLING_PRICE = " + rs.getString("SELLING_PRICE"));
            }

        }
        catch (SQLException e) {
            Utility.trace(m_session, "SQL exception - code: "+String.valueOf(e.getErrorCode())+" "+e.getMessage());
            throw e;
        }
        finally {
            DBAccess.closeEverything(rs, ratesQueryStmt, conn); //DO NOT WORK BECAUSE OF CLOSING CONNECTION (conn)
        }

So first time it works just fine, but when I try call this method twice it shows error 🙁

        DBAccess.getInstance(mySession).getRates("USD"); //WORKS
        DBAccess.getInstance(mySession).getRates("EUR"); // NOT WORKING

error stack

java.lang.NullPointerException
    at oracle.jdbc.dbaccess.DBDataSetImpl._createOrGetDBItem(DBDataSetImpl.java:825)
    at oracle.jdbc.dbaccess.DBDataSetImpl.setBytesBindItem(DBDataSetImpl.java:2520)
    at oracle.jdbc.driver.OraclePreparedStatement.setItem(OraclePreparedStatement.java:1248)
    at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:1690)
    at asteros.DBAccess.getRates(DBAccess.java:141) //ratesQueryStmt.setString(1, id);

if I DO not close connection everything works..

Thank you!

UPD: source of getConnection()

public Connection getConnection() throws Exception {
    Connection conn = null;
    try {

        Utility.trace(m_session, "DB string: "+m_strDBString+" user: "+m_strUser+" password: "+m_strPassword);
        System.out.println("DB string: "+m_strDBString+" user: "+m_strUser+" password: "+m_strPassword);

        Driver dr = new oracle.jdbc.driver.OracleDriver();
        DriverManager.registerDriver(dr);
        conn = DriverManager.getConnection(m_strDBString, m_strUser, m_strPassword);

    } catch (Exception e) {
        throw new Exception(e);
    }

    return conn;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:20:11+00:00Added an answer on May 25, 2026 at 2:20 pm

    PreparedStatement instances are tied to the connection used to prepare them, as far as I’m aware. You can’t use the PreparedStatement after closing the connection, even if you open another one later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.