4 Replies Latest reply on May 2, 2016 6:34 AM by disabled_morkus

    JDBC NullPointerException

    artlujohns

      Hi,

       

      Once in a while I get a NullPointerException while calling prepareStatement() but it does not actually tell me what the error is, there is an exception while initializing an exception!

       

      java.lang.NullPointerException

        at com.filemaker.jdbc.FMSQLException.<init>(Unknown Source)

        at com.filemaker.jdbc.FM_API.prepare(Unknown Source)

        at com.filemaker.jdbc.FM_API.prepare(Unknown Source)

        at com.filemaker.jdbc1.CommonJ1Statement.<init>(Unknown Source)

        at com.filemaker.jdbc2.CommonJ2Statement.<init>(Unknown Source)

        at com.filemaker.jdbc3.CommonJ3Statement.<init>(Unknown Source)

        at com.filemaker.jdbc3.J3PreparedStatement.<init>(Unknown Source)

        at com.filemaker.jdbc3.J3Connection.prepareStatement(Unknown Source)

        at com.filemaker.jdbc2.CommonJ2Connection.prepareStatement(Unknown Source)

       

      Has anyone seen this before? Are there any FM JDBC driver developers here that can help?

       

      Thanks!

        • 1. Re: JDBC NullPointerException
          user19752

          Do you use latest driver and JRE?

          • 2. Re: JDBC NullPointerException

            Yup, I do lots with JDBC and FileMaker. Never gotten this error.

             

            -- What version of FileMaker and its JDBC driver are you using? 

             

                 There were some bugs in the last FMP 13 JDBC driver, but I didn't see this issue. The bug I found was that if you try to read twice from a ResultSet (rather than just copy the value the first read to a variable, for exmaple), the second time, reading from the ResultSet, the value would be empty. FM fixed that issue in FMP 14's version of the JDBC driver.

             

            -- Are you using Windows or Mac?

             

            -- Are you sure you actually have a connection to the database in the first place when you're initializing the PreparedStatement?

             

            Maybe you're closing the connection somewhere in code?

             

            --------------

             

            I normally create a connection like this:

            (read from properties file)

             

            final String FMP_JDBC_DRIVER = props.getProperty("FMP_JDBC_DRIVER");

            final String FMP_DATABASE_URL = props.getProperty("FMP_DATABASE_URL");

            final String fmp_user = props.getProperty("fmp_user");

            final String fmp_password = props.getProperty("fmp_password");

            .

            .

            .

            // establish connection to FileMaker Pro
            fmpConnection = DriverManager.getConnection(FMP_DATABASE_URL, fmp_user, fmp_password);

             

            At this point, the fmpConnection variable should have an object reference in it.

            .

            .

            .

            Then, create your PreparedStatement:

            final java.sql.PreparedStatement fmpPreparedStatement =

               fmpConnection.prepareStatement(<PREPARED_STATEMENT_SQL_HERE>);

             

            (making these variables "final" is just a compiler optimization added after code inspection and won't affect your run/crash results.)

             

            ---

             

            I'm assuming you've stepped through your code and have made sure your have objects at each of the steps above, right?

             

            If you can't get this much working, or some of the code above crashes, post your code and I'll take a look.

             

            I would also test your PreparedStatement SQL to make sure it doesn't have any typos. That's an easy issue to have.

             

            ----

             

            HOPE THIS HELPS.

             

            - m

            • 3. Re: JDBC NullPointerException
              artlujohns

              FM Server 11.05 on Windows in this particular instance. The code is built with the latest driver from FM14.

               

              I may have found the issue in my code, pending confirmation... I found a thread that might execute a query on the main connection concurrently with another thread (a huge no-no for JDBC)

               

              Thank you for your replies

              • 4. Re: JDBC NullPointerException

                Yes, from my double checking, the JDBC spec doesn't guarantee correct results with multi-threading.

                 

                But, in at least one example, the MySQL Connector/J, execute's statements lock the connection with a synchronized block.

                 

                So, if one thread is running a query, other threads using the connection will be blocked until it finishes.

                 

                Depends on your driver, the version of the driver, the version of the JVM, and all the potential race conditions that could occur. If you possibly abstract your database layer with something like "Hibernate" (hibernate.org), it may also help.

                 

                HOPE THIS HELPS.

                 

                - m