JDBC returning empty result set

前端 未结 14 1811
醉话见心
醉话见心 2020-12-15 06:15

I\'m using JDBC for very simple database connectivity.

I have created my connection/statement and executed a query. I check the query object of the statement in the

相关标签:
14条回答
  • 2020-12-15 06:29

    It might be a condition that your table is not committed . Try inserting new records, then commit in your SQL Run Command Window and run your code.

    0 讨论(0)
  • 2020-12-15 06:32

    Please check whether the connection and statement Object alive until you iterate the result set, some times we may close unknowingly.

    0 讨论(0)
  • 2020-12-15 06:37

    In the past I had similar issues in code such as this:

    querystr = "your sql select query string"
    
    resultset = statement.executeQuery(querystr)
    
    while (resultset.next())
    {
    //do something with the data. 
    //if you do something fairly involved in this block (sequentially, in the same thread)
    //such as calling a function that acts on the data returned from the resultset etc.
    //it causes the resultset fetch to wait long enough for resultset.next() to 
    //unexpectedly return null in the middle of everything
    }
    

    What I did in this situation was to load up all data into a local memory data structure with minimum wait on resultset.next(). Then I did whatever I had to on the data from the local data structure after gracefully closing resultset. This behavior was with Oracle 10 on Unix backend/JDK 1.6.0_22 client under Windows XP.

    Hope this helps.

    0 讨论(0)
  • 2020-12-15 06:38

    I figured it out....stupid Oracle didn't like the number of concurrent connections I had (all two of them, one for console, one for java). Unfortunately, the server is not under my control so I will just have to deal with it. You would think that Oracle would provide a better response. Instead it just returned empty result sets.

    Thanks for the responses

    edit Since this was asked/answered there have been a number of people pointed out that the underlying cause is more likely related to the commit/transaction settings in use. Please be sure to see other answers for additional hints and possible solutions.

    0 讨论(0)
  • 2020-12-15 06:38

    For me the problem was that on the creation of the primary key column I had NOT NULL ENABLE. As in ...

    CREATE TABLE SYSTEM_SETTINGS  ( 
      SYSTEM_SETTING_ID NUMBER(9,0) NOT NULL ENABLE, 
        "KEY" VARCHAR2(50 BYTE), 
        "VALUE" VARCHAR2(128 BYTE),
         CONSTRAINT "PK_SYSTEM_SETTINGS" PRIMARY KEY (SYSTEM_SETTING_ID)) 
    TABLESPACE USERS;
    

    When I recreated the table without that as in

    CREATE TABLE SYSTEM_SETTINGS  ( 
      SYSTEM_SETTING_ID NUMBER(9,0), 
        "KEY" VARCHAR2(50 BYTE), 
        "VALUE" VARCHAR2(128 BYTE),
         CONSTRAINT "PK_SYSTEM_SETTINGS" PRIMARY KEY (SYSTEM_SETTING_ID)) 
    TABLESPACE USERS;
    

    It started working via JDBC. I am using ojdbc6.jar for the jdbc driver.

    0 讨论(0)
  • 2020-12-15 06:41

    The same happened to me. I was using SQL Developer to insert test data into my database and test-reading that using JDBC. But all I got was an empty result-set. I could get the column names and all, but had a problem with reading data. As pointed out by dpsthree earlier, I disconnected from the SQL Developer IDE and then it asked me to Commit upon exiting.

    Voila! The problem was that the changes to the databases using the insert command weren't committed.

    For SQL Developer this is located at Preferences > Database > Advanced > Autocommit

    This solved my problem.

    0 讨论(0)
提交回复
热议问题