title: Exception in thread "main" java.lang.NullPointerException error JDeveloper 12c
body: <p>I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.</p>
  
  <p>I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.</p>
  
  <p>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.</p>
  
  <p>I have a java.class file Store_A.java which I have loaded into the ORACLE database with LOADJAVA :</p>
  
  <pre><code>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()); 
      }  
    }
  }
  </code></pre>
  
  <p>Then I have created a procedure which I plan to call out in java:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>And I have a java file that I have created with JDeveloper 12c:</p>
  
  <pre><code>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();
              }
          }
      }
  }
  </code></pre>
  
  <p>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). The line I get error in is </p>
  
  <pre><code>conn.close();
  </code></pre>
  
  <p>How to fix this? </p>
  
  <p>Thank you very much in advance.</p>