1 2 Previous Next 21 Replies Latest reply: Sep 14, 2012 3:09 AM by MrBabakishiyev RSS

    Java Error - Using Tom's code

    LAF
      Hi,

      I'm NEW and don't know anything about JAVA. I'm a PL/SQL programmer. I went and got JAVA code from Tom's Kite site. The code will get all the filenames in a given Directory. Here's the version of Oracle that I'm runing:

      Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
      With the Partitioning and OLAP options
      JServer Release 9.2.0.8.0 - Production

      Here's the JAVA code:
      CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "DirList" as import java.io.*;
          import java.sql.*;
          
          public class DirList
          {
          public static void getList(String directory)
                            throws SQLException
         {
             File path = new File( directory );
             String[] list = path.list();
             String element;
         
             for(int i = 0; i < list.length; i++)
             {
                 element = list;
      #sql { INSERT INTO DIR_LIST (FILENAME)
      VALUES (:element) };
      }
      }

      }
      /


      The DIR_LIST table was created.

      I login SQLPLUS and run this command and I get the following error:

      SQL> exec get_dir_list( 'c:' );
      BEGIN get_dir_list( 'c:' ); END;

      *
      ERROR at line 1:
      ORA-29532: Java call terminated by uncaught Java exception:
      java.lang.NullPointerException
      ORA-06512: at "FW_DEVSQL_APP.GET_DIR_LIST", line 0
      ORA-06512: at line 1


      SQL>


      I know it's NOT CAUSED because the DIRECTORY does not exist. I tried with existing directory and always get the same error !!!


      Please HELP.

      Thanks in advance

      Marc
        • 1. Re: Java Error - Using Tom's code
          linkin
          1. File path = new File( directory );
          and 
          2. for(int i = 0; i < list.length; i++)
          These two sections can through Null pointer exception.Because of the instances "path" and "list" can be null .
          So before doing any operation please check whether they are null or not
          • 2. Re: Java Error - Using Tom's code
            LAF
            Thanks for the quick reply...

            Like I said, I'm ZERO in JAVA. I would put an IF statement to check for NULL, but I don't know any JAVA syntax.

            Thanks!
            • 3. Re: Java Error - Using Tom's code
              J2EE_Life
              You can try with something below:
              CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "DirList" as import java.io.*;
                  import java.sql.*;
                  
                  public class DirList
                  {
                  public static void getList(String directory)
                                    throws SQLException
                 {
                     File path = new File( directory );
              if(path!=null)
                     String[] list = path.list();
                     String element;
                 (if list!=null){
                     for(int i = 0; i < list.length; i++)
                     {
                         element = list;
              #sql { INSERT INTO DIR_LIST (FILENAME)
              VALUES (:element) };
              }
              }
              }

              }
              /
              Hope this time null exception wont come                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
              • 4. Re: Java Error - Using Tom's code
                EJP
                I don't know any JAVA syntax.
                Well asking random questions on a forum is about the most inefficient way you could possibly devise of learning it. Have you considered reading a language manual? tutorial? Java Language Specification?
                • 5. Re: Java Error - Using Tom's code
                  linkin
                  LAF wrote:
                  I would put an IF statement to check for NULL>
                  Yes.
                  LAF wrote:
                  but I don't know any JAVA syntax
                  This is not very tough to write.try it, you can
                  • 6. Re: Java Error - Using Tom's code
                    LAF
                    Got this error:
                    [Error] Compilation (1: 49): ORA-29536: badly formed source: Encountered "[ ] list" at line 11, column 14.
                    Was expecting one of:
                        ";" ...
                        "++" ...
                        "--" ...
                        "." ...
                        "[" <INTEGER_LITERAL> ...
                        "[" <FLOATING_POINT_LITERAL> ...
                        "[" <CHARACTER_LITERAL> ...
                        "[" <STRING_LITERAL> ...
                        "[" "true" ...
                        "[" "false" ...
                        "[" "null" ...
                        "[" "this" ...
                        "[" "super" ...
                        "[" "(" ...
                        "[" "new" ...
                        "[" "void" ...
                        "[" "boolean" ...
                        "[" "char" ...
                        "[" "byte" ...
                        "[" "short" ...
                        "[" "int" ...
                        "[" "long" ...
                        "[" "float" ...
                        "[" "double" ...
                        "[" <IDENTIFIER> ...
                        "[" "+" ...
                        "[" "-" ...
                        "[" "++" ...
                        "[" "--" ...
                        "[" "~" ...
                        "[" "!" ...
                        "[" "#sql" ...
                        "(" ...
                        "[" "]" "[" ...
                        "[" "]" "." ...
                        ":" ...
                        "=" ...
                        "*=" ...
                        "/=" ...
                        "%=" ...
                        "+=" ...
                        "-=" ...
                        "<<=" ...
                        ">>=" ...
                        ">>>=" ...
                        "&=" ...
                        "^=" ...
                        "|=" ...
                        
                    Thanks

                    Marc
                    • 7. Re: Java Error - Using Tom's code
                      linkin
                      J2EE_Life wrote:
                      Hope this time null exception wont come
                      yes,because it failed to compile
                      J2EE_Life wrote:
                      (if list!=null){
                      • 8. Re: Java Error - Using Tom's code
                        J2EE_Life
                        I don have access to oracle now.. U try below:
                        CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "DirList" as import java.io.*;
                            import java.sql.*;
                            
                            public class DirList
                            {
                            public static void getList(String directory)
                                              throws SQLException
                           {
                               File path = new File( directory );
                         String[] list =null;
                        if(path!=null){
                                list = path.list();
                               String element;
                           (if list!=null){
                               for(int i = 0; i < list.length; i++)
                               {
                                   element = list;
                        #sql { INSERT INTO DIR_LIST (FILENAME)
                        VALUES (:element) };
                        }
                        }}
                        }

                        }
                        /
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                        • 9. Re: Java Error - Using Tom's code
                          J2EE_Life
                          Yes true... Thanks
                          • 10. Re: Java Error - Using Tom's code
                            LAF
                            Still an error:
                            [Error] Compilation (1: 49): ORA-29536: badly formed source: Encountered "if" at line 14, column 5.
                            Was expecting one of:
                                "#sql" ...
                                "boolean" ...
                                "byte" ...
                                "char" ...
                                "double" ...
                                "false" ...
                                "float" ...
                                "int" ...
                                "long" ...
                                "new" ...
                                "null" ...
                                "short" ...
                                "super" ...
                                "this" ...
                                "true" ...
                                "void" ...
                                <INTEGER_LITERAL> ...
                                <FLOATING_POINT_LITERAL> ...
                                <CHARACTER_LITERAL> ...
                                <STRING_LITERAL> ...
                                <IDENTIFIER> ...
                                "(" ...
                                "!" ...
                                "~" ...
                                "++" ...
                                "--" ...
                                "+" ...
                                "-" ...
                                
                            [\code]
                            
                            Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                            • 11. Re: Java Error - Using Tom's code
                              linkin
                              Replace this
                              (if list!=null){
                              with
                              if (list!=null){
                              • 12. Re: Java Error - Using Tom's code
                                LAF
                                Problem RESOLVED !!!!!


                                I've put a space between the list and != and path !=. It compiled without ERRORS
                                if(path !=null){
                                        list = path.list();
                                       String element;
                                   if (list !=null){
                                Thank You All for your feedback !


                                Marc
                                • 13. Re: Java Error - Using Tom's code
                                  linkin
                                  welcome
                                  LAF wrote:
                                  I've put a space between the list and != and path !=. It compiled without ERRORS
                                  This is not a space related issue. Its a syntax related issue
                                  • 14. Re: Java Error - Using Tom's code
                                    J2EE_Life
                                    now that the question is solved .. U SHOULD mark it as ANSWERED....
                                    1 2 Previous Next