NullPointerException in PreparedStatement

Hello Friends,
Has anybody encountered this exception...
I get this exception while running the application...
This happen 1 out of 10 times..Cannot say when...?
Message:
java.lang.NullPointerException
Throwable:
java.lang.NullPointerException
at oracle.jdbc.dbaccess.DBData.clearItem(DBData.java:431)
at oracle.jdbc.dbaccess.DBDataSetImpl.clearItem(DBDataSetImpl.java:3528)
at oracle.jdbc.driver.OraclePreparedStatement.checkBindTypes(OraclePreparedStatement.java:3271)
at oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStatement.java:1322)

I think you've answered it yourself,
user setNull or make suer aVar is not null...

Similar Messages

  • NullPointerException on execution/ creation of a PreparedStatement

    Hi,
    I am facing a very weird problem. There is a jar file that is run from the command prompt connecting to SQL Server on the same machine. This program basically does some processing of records within a SQL transaction.
    Sometimes the program ends with a NullPointerException at a PreparedStatement for example on the both record and the transaction is rollbacked .
    Now if I run the program again for the same data, I may get a nullpointer exception at some other record for example on the 250th record.
    Now if you are beginning to feel that there is something wrong with the code then let me tell you this problem ,
    If I run the same jar file on another machine pointing to the earlier mentioned SQL Server and for the same data it runs perfectly fine.
    That is what is giving the creeps. In both the scenarios only thing changing is the machine on which it is being executed and the java version.
    Any Help on the above problem will be highly appreciated
    Thanks,
    Jyothi

    Then you have a race condition.

  • 9.2.0 Thin driver; PreparedStatement.close() gives NullPointerException when close()d

    Here's the error stack:
    --- Nested Exception ---
    java.lang.NullPointerException
    at oracle.jdbc.dbaccess.DBData.clearItem(DBData.java:431)
    at oracle.jdbc.dbaccess.DBDataSetImpl.clearItem(DBDataSetImpl.java:3528)
    at oracle.jdbc.driver.OraclePreparedStatement.clearParameters(OraclePreparedSta
    at com.secretseal.util.sql.PooledPreparedStatement.close(PooledPreparedStatemen
    at com.secretseal.util.sql.LoggableStatement.close(LoggableStatement.java:112)
    Has anybody has this issue? Thank you in advance.

    workaround: use Oracle proprietary batching, setExecuteBatch(). My webapp is facing the exact problem. But I used the Oracle 8i drivers and it worked. Meanwhile, will you please tell me what is the AppServer you are using? Cause this happens in Websphere 4.0.x environment but not in 3.5.x and weblogic.
    Thanks,

  • Getting java.lang.NullpointerException while closing resultset aft using it

    Hi,
    I kindly request to share your ideas reg. my problem.
    I am opening a database connection using connection pool and i am using two or more resultsets and statement objects.I am closing these objects at the end of their usage.But i am getting java.lang.NullpointerException when i close them(if i don't close them it works fine). what might be the reason. Had i did any thing wrong in the code.
    please view the code
    public String storeNewConnection(String CIRCLE,String DIVISION,String SUB_DIVISION,String SECTION,String CONSUMER_NAME,String FATHER_NAME,String STREET_NAME,String DOOR_NO,String TOWN_CITY,String LAND_MARK,String PINCODE,String STDCODE,String PHONE_NO,String EMAIL,String NEIGHBOUR_SCNO,String DOCUMENT_CODE,String LT_APR_NO,String year1,String month1,String day1,String PCBNO,String CONSUMER_STATUS,String SOCIAL_GROUP,String CATEGORY_SUPPLY,String LOCATION_PREMISES,String PURPOSE_OF_SUPPLY,String DURATION,String LOAD_TYPE,String CONNECTED_LOAD,String CONTRACTED_LOAD,String APPLICATION_FEE,String DEVELOPMENT_CHARGES,String SECURITY_DEPOSIT,String ADDL_SECURITY_DESPOSIT,String DEPOSITED_THRU,String DD_CHEQUE_DETAILS,String year2,String month2,String day2,String REMARKS,String POLE_NO)
              int count=0;
              Statement st=null;
              ResultSet rs=null,rs1=null,rs2=null,rs3=null;
              PreparedStatement pst=null;
              String result="",query="",sysDate="",sysDate2="";
              String reg_no = "";
              try
                   st=con.createStatement();
                   //Check dates with sys date
                   String date1 =null;                    
                   String date2 =null;
                   if(! (year1.equals("") || month1.equals("") || day1.equals("")) )
                        date1=day1+"-"+month1+"-"+year1;
                        rs2=st.executeQuery("select round(to_date('"+date1+"','dd-Mon-yyyy')-to_date(sysdate,'dd-Mon-yy')) from dual");
                        rs2.next();
                        if(rs2.getInt(1) != 0)
                             return "false";                              
                   if(! (year2.equals("") || month2.equals("") || day2.equals("")) )
                        date2=day2+"-"+month2+"-"+year2;
                        rs3=st.executeQuery("select round(to_date('"+date2+"','dd-Mon-yyyy')-to_date(sysdate,'dd-Mon-yy')) from dual");
                        rs3.next();
                        if(rs3.getInt(1) != 0)
                             return "false";     
                   rs1=st.executeQuery("select to_char(sysdate,'yyyyMONdd'),to_char(sysdate,'dd-Mon-yyyy') from dual");
                   rs1.next();
                   sysDate=rs1.getString(1);
                   sysDate2=rs1.getString(2);
                   rs=st.executeQuery("select max(SERIAL_NO) from NEW_CONNECTIONS where to_char(sysdate,'yyyy') = to_char(REG_DATE,'yyyy') and to_char(sysdate,'mm') = to_char(REG_DATE,'mm') and SUB_DIVISION_CODE = "+SUB_DIVISION+" and DIVISION_CODE = "+DIVISION+" and CIRCLE_CODE = "+CIRCLE+" ");
                   if(rs.next())
                        count = rs.getInt(1);
                        count++;                              
                   else
                        count=1;
                   query="insert into NEW_CONNECTIONS ( "+
                        " REG_NO,SERIAL_NO,REG_DATE,CIRCLE_CODE,DIVISION_CODE,SUB_DIVISION_CODE,SECTION_CODE, "+
                        " CONSUMER_NAME,FATHER_NAME,STREET_NAME,DOOR_NO,TOWN_CITY,LAND_MARK,PINCODE, "+
                        " STDCODE,PHONE_NO,EMAIL,NEIGHBOUR_SCNO,DOCUMENT_CODE,LT_APR_NO,LT_APR_DATE, "+
                        " PCBNO,CONSUMER_STATUS,SOCIAL_GROUP,CATEGORY_SUPPLY,LOCATION_PREMISES,PURPOSE_OF_SUPPLY,"+
                        " DURATION,LOAD_TYPE,CONNECTED_LOAD,CONTRACTED_LOAD,APPLICATION_FEE,DEVELOPMENT_CHARGES, "+
                        " SECURITY_DEPOSIT,ADDL_SECURITY_DEPOSIT,DEPOSITED_THRU,DD_CHEQUE_DETAILS,DD_CHEQUE_DATE,REMARKS,APPLICATION_STATUS,POLE_NO) "+
                        " values(?,?,'"+sysDate2+"',?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                   pst = con.prepareStatement(query);
                   String cnt ="";
                   if(count <= 9)
                        cnt="0000";
                   else if(count <= 99)
                        cnt="000";
                   else if(count <= 999)
                        cnt="00";
                   else if(count <= 9999)
                        cnt="0";
                   cnt+=Integer.toString(count);
                   reg_no = CIRCLE+DIVISION+SUB_DIVISION+SECTION+"N"+cnt+sysDate;               
                   int serial_no =count;
                   int pin = 0;
                   if(!PINCODE.equals(""))
                        pin =Integer.parseInt(PINCODE);
                   int std = 0;
                   if(!STDCODE.equals(""))
                        std = Integer.parseInt(STDCODE);
                   int status = Integer.parseInt(CONSUMER_STATUS);
                   int social_group = Integer.parseInt(SOCIAL_GROUP);
                   int supply = Integer.parseInt(CATEGORY_SUPPLY);
                   int location = Integer.parseInt(LOCATION_PREMISES);
                   int purpose = Integer.parseInt(PURPOSE_OF_SUPPLY);
                   int duration = Integer.parseInt(DURATION);
                   int laod_type = Integer.parseInt(LOAD_TYPE);
                   float conn_load = Float.parseFloat(CONNECTED_LOAD);
                   int cont_load = 0;
                   if(!CONTRACTED_LOAD.equals(""))
                        cont_load =Integer.parseInt(CONTRACTED_LOAD);
                   int app_fee = Integer.parseInt(APPLICATION_FEE);
                   int dev_chg = Integer.parseInt(DEVELOPMENT_CHARGES);
                   int sec_dep = Integer.parseInt(SECURITY_DEPOSIT);
                   int addl_sec_dep = 0;     
                   if(!ADDL_SECURITY_DESPOSIT.equals(""))
                        addl_sec_dep =Integer.parseInt(ADDL_SECURITY_DESPOSIT);
                   int dep_thru = Integer.parseInt(DEPOSITED_THRU);          
                   pst.setString(1,reg_no);
                   pst.setInt(2,serial_no);
                   pst.setString(3,CIRCLE);
                   pst.setString(4,DIVISION);
                   pst.setString(5,SUB_DIVISION);
                   pst.setString(6,SECTION);
                   pst.setString(7,CONSUMER_NAME);
                   pst.setString(8,FATHER_NAME);
                   pst.setString(9,STREET_NAME);
                   pst.setString(10,DOOR_NO);
                   pst.setString(11,TOWN_CITY);
                   pst.setString(12,LAND_MARK);
                   pst.setInt(13,pin);
                   pst.setInt(14,std);
                   pst.setString(15,PHONE_NO);
                   pst.setString(16,EMAIL);
                   pst.setString(17,NEIGHBOUR_SCNO);
                   pst.setString(18,DOCUMENT_CODE);
                   pst.setString(19,LT_APR_NO);
                   pst.setString(20,date1);
                   pst.setString(21,PCBNO);
                   pst.setInt(22,status);
                   pst.setInt(23,social_group);
                   pst.setInt(24,supply );
                   pst.setInt(25,location);
                   pst.setInt(26,purpose);
                   pst.setInt(27,duration);
                   pst.setInt(28,laod_type);
                   pst.setFloat(29,conn_load );
                   pst.setInt(30,cont_load);
                   pst.setInt(31,app_fee);
                   pst.setInt(32,dev_chg);
                   pst.setInt(33,sec_dep);
                   pst.setInt(34,addl_sec_dep);
                   pst.setInt(35,dep_thru );
                   pst.setString(36,DD_CHEQUE_DETAILS);
                   pst.setString(37,date2);
                   pst.setString(38,REMARKS);
                   pst.setInt(39,1);
                   pst.setString(40,POLE_NO);
                   pst.executeUpdate();
                   result=reg_no;                                   
                   rs.close();
                   rs=null;
                   rs1.close();
                   rs1=null;
                   rs2.close();
                   rs2=null;
                   rs3.close();
                   rs3=null;
                   st.close();
                   st=null;
                   pst.close();
                   pst=null;
              catch(Exception e)
                   e.printStackTrace();
                   result="false";
                   return result;
              finally
                   if (rs != null)
                        try
                             rs.close();
                        catch (SQLException e)
                        rs = null;
                   if (rs1 != null)
                        try
                             rs1.close();
                        catch (SQLException e)
                        rs1 = null;
                   if (rs2 != null)
                        try
                             rs2.close();
                        catch (SQLException e)
                        rs2 = null;
                   if (rs3 != null)
                        try
                             rs3.close();
                        catch (SQLException e)
                        rs3 = null;
                   if (st != null)
                        try
                             st.close();
                        catch (SQLException e)
                        st = null;
                   if (pst != null)
                        try
                             pst.close();
                        catch (SQLException e)
                        pst = null;
              return result;
    Also plz help me to improve the code if necessary so that it will work fine for multiple users
    thaks & regards
    Prasanth.C

    Thanks a lot.
    i replaced the code below
    if (rs != null)
                        try
                             rs.close();
                        catch (SQLException e)
                        rs = null;
                   if (rs1 != null)
                        try
                             rs1.close();
                        catch (SQLException e)
                        rs1 = null;
                   if (rs2 != null)
                        try
                             rs2.close();
                        catch (SQLException e)
                        rs2 = null;
                   if (rs3 != null)
                        try
                             rs3.close();
                        catch (SQLException e)
                        rs3 = null;
                   if (st != null)
                        try
                             st.close();
                        catch (SQLException e)
                        st = null;
                   if (pst != null)
                        try
                             pst.close();
                        catch (SQLException e)
                        pst = null;
    instead of blindly closing the resultsets and statements
    now it works fine.
    One more thing, is my code structurally correct, i mean the variables, try...catch blocks,results,statements,database connections and overall coding. whether it looks like professional code.
    thaks & regards,
    Prasanth.C

  • PreparedStatement problem in Oracle OTD(JCAPS 5.1.3)

    Hi,
    I encountered a problem with Oracle-eway-generated PreparedStatements when trying to build a project in enterprise designer . I know that without using any prepraredstatement, my project builds fine. Below is the text on the error pop-up window:
    java.lang.NullPointerException
    at com.stc.codegen.OTDImpl.model.OTDCodeletFactory$ArtifactKey.hashCode(OTDCodeletFactory.java:136)
    at java.util.HashMap.hash(HashMap.java:261)
    at java.util.HashMap.containsKey(HashMap.java:339)
    at com.stc.codegen.OTDImpl.model.OTDCodeletFactory.getOtdFromBuisnessProcess(OTDCodeletFactory.java:207)
    at com.stc.codegen.OTDImpl.model.OTDCodeletFactory.createCodelets(OTDCodeletFactory.java:285)
    at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.process(DeploymentVisitorImpl.java:382)
    at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.process(DeploymentVisitorImpl.java:308)
    at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.traverseDeployment(DeploymentVisitorImpl.java:268)
    at com.stc.codegen.driver.module.DeploymentBuildAction.loadCodeGen(DeploymentBuildAction.java:923)
    at com.stc.codegen.driver.module.DeploymentBuildAction.access$1000(DeploymentBuildAction.java:174)
    at com.stc.codegen.driver.module.DeploymentBuildAction$1.run(DeploymentBuildAction.java:599)
    at org.openide.util.Task.run(Task.java:136)
    [catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:599)In order to isolate the problem, I have created a simplified project which just reads a text message and writes the message into the Oracle database with the help of a PreparedStatement. I had an error as well;
    "Oracle eway code generation error(ERROR_CODEGEN_BPEL_CODELET_GENERAL)"
    Caused by: com.stc.codegen.framwork.model.CodeGenException: Error when generating OTD code ...Exception: Invalid parameter type: Class: [TEST] Object: [Param1] Param Type: [VARCHAR].(ERROR_CODEGEN_DB)(ERROR_CREATE_OTD)I think that there is a conflict between the parameters in Oracle and the parameters in the code. Somehow, Oracle eway cannot get the parameter type from database correctly.
    Is there a solution for this? I couldn't find any patches/updates for Enterprise designer or eway. Can you point me to right direction if there is any.
    Thanks in advance,
    Mete

    Hi there,
    (I think) I have found the solution. When designing OTD, I have mapped VARCHAR2 column as CHAR. Somehow, JCAPS throws a code generation exception if the field is not mapped as a CHAR for a VARCHAR2 database column.

  • Bug in Oracle JDBC Driver: NullPointerException when calling clearParameters

    There is a bug in the latest version of the JDBC driver that throws a NPE when calling PreparedStatement.clearParameters(). I don't need a response to this, since I have a workaround (just catching and ignoring the exception), but it should probably be fixed. I speculate that the problem only occurs when you try to call clearParameters() more than once on the same PS, but I haven't confirmed it.
    It is probably an easy fix. Following is the stack trace:
    java.lang.NullPointerException
    at oracle.jdbc.dbaccess.DBData.clearItem(DBData.java:431)
    at oracle.jdbc.dbaccess.DBDataSetImpl.clearItem(DBDataSetImpl.java:3528)
    at oracle.jdbc.driver.OraclePreparedStatement.clearParameters(OraclePreparedStatement.java:3401)
    at com.solarmetric.datasource.PreparedStatementCache$CachePreparedStatement.close(PreparedStatementCache.java:293)
    at com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executePreparedStatementBatch(SQLExecutionManagerImpl.java:666)
    at com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executePreparedStatement(SQLExecutionManagerImpl.java:514)
    at com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executeInternal(SQLExecutionManagerImpl.java:406)
    at com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.flush(SQLExecutionManagerImpl.java:273)
    at com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.flush(JDBCStoreManager.java:421)
    at com.solarmetric.kodo.runtime.PersistenceManagerImpl.flush(PersistenceManagerImpl.java:549)
    at com.solarmetric.kodo.runtime.PersistenceManagerImpl.commit(PersistenceManagerImpl.java:412)
    at com.sun.jdotck.api.persistencemanager.MakePersistentAssignsObjectId.testMakePersistentAssignsObjectId2(Unknown Source)
    at com.sun.jdotck.api.persistencemanager.MakePersistentAssignsObjectId.testMakePersistentAssignsObjectId(Unknown Source)
    at com.sun.jdotck.api.persistencemanager.MakePersistentAssignsObjectId.runTest(Unknown Source)
    at com.sun.jdotck.api.persistencemanager.PersistenceManagerTest.run(Unknown Source)
    at com.solarmetric.kodo.compatibility.JDOCompatabilityTestSuite$1.runTest(JDOCompatabilityTestSuite.java:493)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:325)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:524)
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

    Take a look at the method that is causing the NullPointerException:
    public void clearItem(int i)
    if (!m_dynamic && m_vector == null && i < m_vector.size())
    m_vector.removeElementAt(i);
    if (m_items != null && i >= m_items.length)
    return;
    m_items[i] = null;
    return;
    A NullPointerException will be thrown whenever clearParameters() is called when no parameters have yet been bound.
    The first IF statement should read:
    if (!m_dynamic && m_vector != null && i < m_vector.size())
    A simple workaround would be to make sure that your parameter list is never empty before calling clearParameters(). Is there a patch for this anywhere?

  • Jdbc NullPointerException calling pl/sql procedure from java

    Hi.
    Getting the following exception calling a plsql procedure from jdbc.
    - Jdbc version is 10.2.0.2, but it also happens running several other variants, including 10.1.0.5.0.
    - Application is running in Weblogic 8.1.3 (8.1 SP 3).
    The procedure call itself has 2 in/out parameters which are tables (actually just 1 dimensional arrays), which I'm suspecting has something to do with the problem. I can successfully call this procedure using a plsql developer tool with the same bind parameters.
    Any ideas?
    Exception encountered while executing PL/SQL procedure MVT_Web_Inquiry.ShowInquiry:
    java.lang.NullPointerException at oracle.jdbc.driver.T4CTTIiov.processRXD([Loracle.jdbc.driver.Accessor;I[B[C[SILoracle.jdbc.driver.DBConversion;[B[B[[Ljava.io.InputStream;[[[B[[Loracle.jdbc.oracore.OracleTypeADT;Loracle.jdbc.driver.OracleStatement;[B[C[S)[Loracle.jdbc.driver.Accessor;(T4CTTIiov.java:139)
    at oracle.jdbc.driver.T4C8Oall.receive()V(T4C8Oall.java:521)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(ZZZZ)V(T4CCallableStatement.java:215)
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(Z)V(T4CCallableStatement.java:1119)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout()V(OracleStatement.java:1278)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal()I(OraclePreparedStatement.java:3446)
    at oracle.jdbc.driver.OraclePreparedStatement.execute()Z(OraclePreparedStatement.java:3552)
    at oracle.jdbc.driver.OracleCallableStatement.execute()Z(OracleCallableStatement.java:5261)
    at weblogic.jdbc.wrapper.PreparedStatement.execute()Z(PreparedStatement.java:70)
    at
    [snip]

    OK... I figured it out.
    Apparently, this error happens when you forget to register the output part of an in/out parameter. I would have hoped for better error messaging, but oh well.
    -ed-

  • Java.lang.NullPointerException with and update statement

    Hello,
    I'm getting this exception:
    java.lang.NullPointerException
         phaseone.AlbumModel.updateImageTrackerAlbums(AlbumModel.java:313)
         phaseone.AlbumModel.processRequest(AlbumModel.java:228)
         phaseone.AlbumModel.doGet(AlbumModel.java:522)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    I have an open method called before this one that connects me to the database. It works fine and have it working with a bunch of other methods but this one gives me this exception. i've even hard coded the variable 'user' and 'albumNumber' with information that exists in the database. i can't see where this logical error is coming from. I appreciate the help. I've been on this for 3 1/2 hour going blind. thanks!!
    public boolean updateImageTrackerAlbums(String user, int albumNumber){
              PreparedStatement pstmt = null;
              boolean pass = false;
              String query = "update imagetracker set totalalbums = ? where username = ?";
              try{
              pstmt = conn.prepareStatement(query);
              pstmt.setInt(1, albumNumber);
              pstmt.setString(2, user);
             int x = pstmt.executeUpdate();
             if (x >= 1){
             pass = true;
              }catch(SQLException e){
                e.printStackTrace();
                return pass;
              }finally{
              DBUtil.closePreparedStatment(pstmt);
              return pass;
              }

    code3 wrote:
    The exception is pointing to this:
    pstmt = conn.prepareStatement(query);
    Do you understand anyway when a NullPointerException would be thrown? It will be thrown if you try to access/invoke an object reference which is actually null.
    Connection conn = null;
    pstmt = conn.prepareStatement(query); // Throws NPE because conn is null.

  • Exception in thread "main" java.lang.NullPointerException error JDeveloper 12c

    Hello,
    I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.
    I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.
    I have a table "Beer" and I want to select all the data out with a stored procedure which I call out of Java app.
    I have a java.class file Store_A.java which I have loaded into the ORACLE database with LOADJAVA :
        import java.sql.*;
        import java.io.*;
        public class Store_a {
          public static void apskatit ()
            throws SQLException
            { String sql =
              "SELECT * FROM Beer";
            try { Connection conn = DriverManager.getConnection("jdbc:default:connection:");
              PreparedStatement pstmt = conn.prepareStatement(sql);
              ResultSet rset = pstmt.executeQuery();
              rset.close();
              pstmt.close();
            catch (SQLException e) {System.err.println(e.getMessage());
    Then I have created a procedure which I plan to call out in java:
        CREATE OR REPLACE PACKAGE Store_a AS
        PROCEDURE apskatit;
        END Store_a;
        CREATE OR REPLACE PACKAGE BODY Store_a AS
        PROCEDURE apskatit AS LANGUAGE JAVA
        NAME 'Store_a.apskatit()';
        END Store_a;
    And I have a java file that I have created with JDeveloper 12c:
        import java.sql.Connection;
        import java.sql.DriverManager;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        public class Class1 {
             * @param args
            public static void main(String[] args) throws SQLException {
                Connection conn = null;
                try {
                    Class.forName("oracle.jdbc.driver.OracleDriver");
                    //Izveidojam savienojumu
                    conn = DriverManager.getConnection("jdbc.oracle.thin:@localhost:1521", "SYSTEM", "asdasd");
                    // Izveidojam callable statement
                    CallableStatement stmt = conn.prepareCall("CALL Store_a.apskatit()");
                    ResultSet resul = stmt.executeQuery();
                    while (resul.next()) {
                        System.out.println(resul.getInt(1) + "\t" + resul.getString(2));
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
    When I try to run the java file, I get this error "Exception in thread "main" java.lang.NullPointerException at client.Class1.main(Class1.java:29).
    So the line I get error in is "conn.close();"
    How to fix this?
    Thank you very much in advance.

    I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.
    I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.
    Maybe you haven't read it yet but I told you in your other thread what you were doing wrong and, step by step, how to address the problem.
    https://forums.oracle.com/thread/2611124
    I'm not going to repeat everything again just this one main piece of advice:
    Until you get you code working outside the database don't even bother trying to load it into the DB and create a Java stored procedure.
    You are trying to deal with too many different issues at the same time. Unless you solve your primary Java problem by fixing the code outside the DB you will have nothing but problems loading it into the DB.
    And just get rid of this line of code - you don't need it anymore and it hasn't been done like that for many years now:
    Class.forName("oracle.jdbc.driver.OracleDriver");

  • HELP!!!!  java.lang.NullPointerException

    HELP!!!!
    java.lang.NullPointerException
    at csc.util.SQLstatement.prepStatement(SQLstatement.java:24)
    at csc.util.dbutil.DBprcslogEnd(dbutil.java:713)
    at tr_fets_ck.processMain(tr_fets_ck.java:266)
    at tr_fets_ck.main(tr_fets_ck.java:175)
    java.lang.NullPointerException
    at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
    at java.sql.DriverManager.getConnection(DriverManager.java:525)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at tr_fets_ck.processMain(tr_fets_ck.java:183)
    at tr_fets_ck.main(tr_fets_ck.java:175)
    I can run my code using jdeveloper 10g using a default file and everything works fine but when I run my code in the production environment I get the error listed above.
    Here's portions of the code.
    public void processMain(csc.util.SQLstatement sq, String filename) {
    try {
    // Connect to the database
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DriverManager.getConnection("jdbc:odbc:TEST","test","test4xml");
    // Open specified file
    if (xu.Check_File_Processed(conn, filename)){
    xu.WriteXMLProblem("FAILURE", err, "N/A", "FILE " filename " HAS ALREADY BEEN RUN SUCCESSFULLY","https://msis.k12.ms.us/SAP/MSIS_err.html#87");
    UpdateFETSDistrict(conn, "N", filename, district, year, sq);
    xu.Process_Results_Report(conn,err,filename);
    conn.commit();
    conn.close();
    System.exit(0);
    The code that I think is generating the error is:
    if (CheckYearInd(conn,district, year, sq)) {
    xu.WriteXMLProblem("FAILURE", err, "N/A", "FILE " filename " PREVIOUS YEAR DATA HAS ALREADY BEEN COMPLETED","https://msis.k12.ms.us/SAP/MSIS_err.html#87");
    UpdateFETSDistrict(conn, "N", filename, district, year, sq);
    xu.Process_Results_Report(conn,err,filename);
    conn.commit();
    conn.close();
    System.exit(0);
    public static boolean CheckYearInd (Connection conn,
    String district,
    String year,
    csc.util.SQLstatement sqs)
    // check the FETS_DISTRICT_APPROVAL table for a record.
    // Return FALSE if previous year data exists = Y.
    // Return TRUE if no record exists
    throws SQLException
    PreparedStatement pstmt1 = null;
    String SQLString = "select count(rowid) from FETS_DISTRICT_APPROVAL" +
    " where DISTRICT_NUMBER = ? and "+
    " YEAR = ? and " +
    " BOND_DATA_IND = 'Y' and "+
    " STATE_APPROVAL_STATUS = 'COMPLETED' and "+
    " REQ_RESUBMISSION = 'N' ";
    // System.out.println(SQLString);
    pstmt1 = sqs.prepStatement(conn,SQLString);
    pstmt1.setString(1,district);
    pstmt1.setString(2,year);
    ResultSet rset = pstmt1.executeQuery();
    rset.next ();
    if (rset.getInt(1) > 0) {
    rset.close();
    return false;
    } else {
    rset.close();
    return true;
    } // end CheckYearProcessed 

    package csc.util;
    import java.io.*;
    import java.math.*;
    import java.sql.*;
    import java.util.Vector;
    public class SQLstatement {
    Vector vSQL_string = new Vector();
    Vector vSQL_stmt = new Vector();
    public PreparedStatement prepStatement(Connection conDB, String strSQL)
    throws SQLException {
    PreparedStatement pstmt = null;
    try{
    int intSQLIndex = vSQL_string.indexOf(strSQL);
    if (intSQLIndex != -1) {
    line 24==> pstmt = (PreparedStatement)vSQL_stmt.elementAt(intSQLIndex);
    } else {
    pstmt = conDB.prepareStatement(strSQL);
         vSQL_string.addElement(strSQL);
         vSQL_stmt.addElement(pstmt);
    return pstmt;
    } catch (SQLException e) {
    System.err.println (e.getMessage()); // detail message
    System.err.println ("* SQL ERROR * strSQL="+strSQL);
    throw e;
    } // end prepStatement()
    } // end class SQLstatement

  • Java.lang.NullPointerException when using DataSource connection and executing CallableStatement

    Hi Guys
    I am having some problem as I am using a DataSource for connections and randomly
    the CallableStatements and PreparedStatements created from this DataSource becomes
    null and everytime I get NullPointerException with this message.
    java.sql.SQLException: java.lang.NullPointerException
         at weblogic.jdbc.rmi.SerialPreparedStatement.setString(SerialPreparedStatement.java:210)
         at .........
    Help will be appreciated..

    Hi Guys
    I am having some problem as I am using a DataSource for connections and randomly
    the CallableStatements and PreparedStatements created from this DataSource becomes
    null and everytime I get NullPointerException with this message.
    java.sql.SQLException: java.lang.NullPointerException
         at weblogic.jdbc.rmi.SerialPreparedStatement.setString(SerialPreparedStatement.java:210)
         at .........
    Help will be appreciated..

  • Java.lang.NullPointerException when doing SQL on ms access

    I am trying to perform Insert and delete commands on an access database and I continue to get a java.lang.NullPointerException when performing the action. Everything is fine when i do a Select * FROM..., I am able to read all of the information I ask for, but when performing the Insert/Delete commands I get the error. Any help would be appreciated, I will copy and past a portion of my code below. All of the fields and variable types match with what is in the database.
    public void executeAddSecretary() throws SQLException{
    String a,b;
    a= txtSecLname.getText();
    b= txtSecFname.getText();
    statement.execute("INSERT INTO Contact_Sec (Sec_Lname,Sec_Fname) Values ('" + a + "', '" + b + "')");
    System.out.println("updated Secretary");
    public void executeDeleteContact() throws SQLException{
    String a = "a";
    statement.execute("DELETE FROM Contact WHERE Lname = ('" + a + "')");
    System.out.println("deleted contact");
    Thanks to anyone who can help me out.

    1) Use prepared statement instead of statement.
    2) Do like this ...
    PreparedStatement prepStmt = null;
    try
         String query="INSERT INTO Contact_Sec (Sec_Lname,Sec_Fname) Values (?,?)");
         prepStmt = connection.prepareStatement(query);
         prepStmt.setString(1, value1);
         prepStmt.setString(2, value2);
         prepStmt.executeUpdate();
    catch (SQLException e)
         throw e;
    catch (Exception e)
         throw e;
    finally
         try
              if (prepStmt != null)
                   prepStmt.close();
         } catch (Exception e) {}
         try
              if (connection != null)
                   connection.close();
         } catch (Exception e) {}
    }3) If you still get the null exception then put step wise System.out's
    and debug it.
    -Rohit

  • Intermittent NullPointerException while calling connection.prepareStatement("insert into mytable (myuid, foo) values (SEQ_M_MSG_UID.nextval,?)");

    Hello,
    I am intermittently getting a nullpointer exception while parsing a
    query to make a preparedStatement. I am using WebLogic5.1 sp9.
    Oracle 817. Java 1.3.1 The code is very simple (although the
    setTypeMap(getTypeMap) stuff is there for ugly historical reasons, it
    has been included for completeness). Any insight into this problem
    would be greatly appreciated.
    My only current theory is that it is related to the nextval being
    passed in the string to the prepareStatement.
    The exception only happens 1 in 2000 calls. This code usually
    succeeds. The code is executing in the context of a stateless session
    bean. There may be upto 200 client threads calling this method
    concurrently from various systems.
    ...dAmOn
    CODE:
    final String lQuery = "insert into SB_MESSAGE (M_MSG_UID,
    M_MSG_GUID, M_REQUESTOR_GUID, M_MSG_GROUP, M_MSG_REQ_GUID,
    M_DEVICE_UID, M_ACCT_UID, M_TASK_ID, M_COMPLETION_STATUS,
    M_LAST_STATE, M_FILTER_NAME, M_FINAL_ATTEMPT, M_START_TIME,
    M_COMPLETED_TIME, M_TLM_DT)
    values(SEQ_M_MSG_UID.nextval,?,?,?,?,?,?,?,?,?,?,'F',?,?,?) ";
    PreparedStatement lPs = null;
    Driver driver =
    (Driver)Class.forName("weblogic.jdbc20.jts.Driver").newInstance();
    Connection connection =
    driver.connect("jdbc20:weblogic:jts:myPool", null);
    connection.setTypeMap(connection.getTypeMap());
    // ** This line leads to the stack trace following the line **
    lPs = connection.prepareStatement(lQuery);
    Stack Trace:
    java.sql.SQLException: java.lang.NullPointerException
    at oracle.jdbc.driver.OracleConnection.nativeSQL(OracleConnection.java:762)
    at oracle.jdbc.driver.OracleStatement.expandSqlEscapes(OracleStatement.java:4790)
    at oracle.jdbc.driver.OracleStatement.parseSqlKind(OracleStatement.java:4779)
    at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:209)
    at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:165)
    at oracle.jdbc.driver.OracleConnection.privatePrepareStatement(OracleConnection.java:604)
    at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:485)
    at weblogic.jdbc.common.internal.ConnectionEnv.getStatementHolderForCachedPrepared(ConnectionEnv.java:99)
    at weblogic.jdbcbase.jts.Connection.prepareStatement(Connection.java:138)

    Hi. That's clearly an Oracle driver bug. I suggest downloading the latest driver from
    Oracle, and making sure it's ahead of all weblogic stuff in the server's weblogic.classpath,
    by editing the startWeblogic script.
    Joe
    Damon Weinstein wrote:
    Hello,
    I am intermittently getting a nullpointer exception while parsing a
    query to make a preparedStatement. I am using WebLogic5.1 sp9.
    Oracle 817. Java 1.3.1 The code is very simple (although the
    setTypeMap(getTypeMap) stuff is there for ugly historical reasons, it
    has been included for completeness). Any insight into this problem
    would be greatly appreciated.
    My only current theory is that it is related to the nextval being
    passed in the string to the prepareStatement.
    The exception only happens 1 in 2000 calls. This code usually
    succeeds. The code is executing in the context of a stateless session
    bean. There may be upto 200 client threads calling this method
    concurrently from various systems.
    ...dAmOn
    CODE:
    final String lQuery = "insert into SB_MESSAGE (M_MSG_UID,
    M_MSG_GUID, M_REQUESTOR_GUID, M_MSG_GROUP, M_MSG_REQ_GUID,
    M_DEVICE_UID, M_ACCT_UID, M_TASK_ID, M_COMPLETION_STATUS,
    M_LAST_STATE, M_FILTER_NAME, M_FINAL_ATTEMPT, M_START_TIME,
    M_COMPLETED_TIME, M_TLM_DT)
    values(SEQ_M_MSG_UID.nextval,?,?,?,?,?,?,?,?,?,?,'F',?,?,?) ";
    PreparedStatement lPs = null;
    Driver driver =
    (Driver)Class.forName("weblogic.jdbc20.jts.Driver").newInstance();
    Connection connection =
    driver.connect("jdbc20:weblogic:jts:myPool", null);
    connection.setTypeMap(connection.getTypeMap());
    // ** This line leads to the stack trace following the line **
    lPs = connection.prepareStatement(lQuery);
    Stack Trace:
    java.sql.SQLException: java.lang.NullPointerException
    at oracle.jdbc.driver.OracleConnection.nativeSQL(OracleConnection.java:762)
    at oracle.jdbc.driver.OracleStatement.expandSqlEscapes(OracleStatement.java:4790)
    at oracle.jdbc.driver.OracleStatement.parseSqlKind(OracleStatement.java:4779)
    at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:209)
    at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:165)
    at oracle.jdbc.driver.OracleConnection.privatePrepareStatement(OracleConnection.java:604)
    at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:485)
    at weblogic.jdbc.common.internal.ConnectionEnv.getStatementHolderForCachedPrepared(ConnectionEnv.java:99)
    at weblogic.jdbcbase.jts.Connection.prepareStatement(Connection.java:138)

  • 3 columns in table, but just 2 field in edit page = NullpointerException

    Hi!
    I have a h:dataTable with 3 columns (modul_id, modul_name, synonym_name), but i want to edit just 2 fields in the edit page: modul_name, synonym_name.
    I must call an UPDATE sql statement, when the user click to submit and I need the value of modul_id as well.
    UPDATE nxt_moduls SET modul_name=?,synonym_name=? WHERE modul_id=?But when I want to set the value of modul_id for PreparedStatement, I get a NullpointerException, the modul_id is null.
    There are just two inputText on the edit.jsp one for modul_name and one for synonym_name. I think, that I must return the value of modul_id somwhow as well. When I put a third inputText for modul_id, then it worked, but I don't want to allow to edit this.
    This is my edit.jsp:
    <html>
         <body>
              <f:view>
                   <h:form>
                        <h:panelGrid columns="2">
                             <h:outputText value="Module name"/>
                             <h:inputText id="modul_name" value="#{nxtModulsBean.itemNxtModuls.modul_name}"/>
                             <h:outputText value="Synonym name"/>
                             <h:inputText id="synonym_name" value="#{nxtModulsBean.itemNxtModuls.synonym_name}"/>
                        </h:panelGrid>
                        <h:commandButton action="#{nxtModulsBean.saveItemNxtModuls}" value="Save"/>
                   </h:form>
              </f:view>
         </body>
    </html>and this is the java code for save operation:
         void updateNxtModulsInDB() throws SQLException, NamingException {
              String sql = new String("UPDATE nxt_moduls SET modul_name=?,synonym_name=? WHERE modul_id=?");
              java.sql.PreparedStatement PreStat = ownGetConnection().prepareStatement(sql);
              PreStat.setString(1,itemNxtModuls.getModul_name());
              PreStat.setString(2,itemNxtModuls.getSynonym_name());
              PreStat.setLong(3,itemNxtModuls.getModul_id());
              PreStat.execute();
              PreStat.close();
              ownGetConnection().commit();
         }here stops: PreStat.setLong(3,itemNxtModuls.getModul_id());
    Please help me!
    Thanks!

    I've solved the problem: the <managed-bean-scope> tag of bean was defined in the faces-config.xml as 'request' and not 'session'. When I set to 'session', it functioned perfectly...

  • NullPointerException  becuase of

    hello
    I try to use LIKE operator in SQL query
    String fn="myName"
    SELECT * FROM Person WHERE Firstname LIKE '%?%'
    ps.setString(1, fn);but I becom an java.lang.NullPointerException
    whay

    Here is the whole code n i tried it out and it works.it returns the filed
    AB CD
    import java.sql.*;
    import java.util.ArrayList;
    public class TestT
    public static void main(String[] args)
    // change this to whatever your DSN is
    String dataSourceName = "dataBase";
    String dbURL = "jdbc:odbc:" + dataSourceName;
    ArrayList resu = new ArrayList();
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String filename = "D:\\Datbase\\COFFEES.mdb";
    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
    Connection con = DriverManager.getConnection( database ,"","");
    String myname = "%CD%";
    PreparedStatement updateSales;
    String query = "SELECT * FROM Person WHERE Firstname WHERE COF_NAME like ?";
    updateSales = con.prepareStatement(query);
    updateSales.setString(1,myname);
    updateSales.executeQuery();
    ResultSet rs = updateSales.getResultSet(); // get any ResultSet that came from our query
    if (rs != null) // if rs == null, then there is no ResultSet to view
    while ( rs.next() ) // this will step through our data row-by-row
    String First_NAME = rs.getString("First_NAME");
    System.out.println("First_NAME = > "+ First_NAME);
    updateSales.close();
    con.close();
    } catch (Exception err) {
    System.out.println( "Error: " + err );
    }

Maybe you are looking for

  • TAXINN related

    Hi Any idea for some basic ideas about TAXINN and how different is it from TAXINJ. In TAXINJ we create calculations schemas and attach these schemas to vendors. Then using FTXP we maintain taxes. In taxINN how is tcode FV11 used and what role FTXP ha

  • Programmed binding in workflow

    i had to do calculation with in programmed binding . can any one help me to do it . regards kamal

  • How to stop scrolling on screen

    Hi all, I've created screen which is big enough for scrollbars to show up. Problem is that when user move down to change some field and he enforce PAI to being executed (by example by pressing F4), scroll is returning to it's initial position. How ca

  • 8.1 update for iPad Mini, worth it?

    Haven't downloaded it yet because the 8 update slowed everything to a crawl and I was told the only way to get it back in shape was to wipe to factory and then install apps one at a time......how many hours a day do they think I have (I went to the g

  • Catching Connection Limit Event

    We are using the developer version of Flash Media Server 3.02 and want to have our client gracefully fail when the server hits its max 10 connections. I want to display an error saying we are using all available connections right now but I do not kno