Results 1 to 2 of 2
  1. #1
    sweetvalley is offline Member
    Join Date
    Mar 2016
    Posts
    2
    Rep Power
    0

    Default eBay JDBC - Null pointer exception

    I am attempting to download the results from eBay GetSellerTransactions, and insert the results in an Access database. I am able to return results into a Java table, however, I can't seem to find how to insert the results into an Access database. The ODBC connection is fine in a test example, so I think the error is not the connection to the database, but rather pulling the data from eBay.

    With this code, I am receiving a null pointer exception:

    Java Code:
       public void UpdateAccess() throws Exception{
             Connection con=null;
             PreparedStatement stamt=null;
             try{
             
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             String dataSourceName = "JdbcOdbc";
             String dbURL = "jdbc:odbc:" + dataSourceName;
             con = DriverManager.getConnection(dbURL);
             
             StringBuilder insertQuery=new StringBuilder("INSERT INTO tblTest ")
                     .append("(TestField) ")
                     .append("VALUES (?);");
             stamt=con.prepareStatement(insertQuery.toString());
             
             //Null pointer exception starts here I believe
             TransactionType transa = new TransactionType();
             UserType buyer = transa.getBuyer();
             String FirstName = buyer.getUserFirstName();
             stamt.setString(0, FirstName); 
             }
         
                    catch (Exception err) {
                 System.out.println("ERROR: " + err);
             }
             finally{ 
                 try{con.close();} catch(Exception e){System.out.println("ERROR: " + e);}}
         
         }

    This is how I am calling this method, after the display results Java command:

    Java Code:
          // Display results.
               this.txtCount.setText(pnresult.getTotalNumberOfEntries().toString());
         
               this.txtHasMoreItems.setText(api.getHasMoreTransactions() ? "yes" : "no");
               this.txtTotalNumberOfPages.setText(
                 pnresult.getTotalNumberOfPages() == null ? "" : pnresult.getTotalNumberOfPages().toString());
         
               String actualCountTxt = new Integer(api.getReturnedTransactionCountActual()).toString();
               this.txtReturnedItemCountActual.setText(actualCountTxt);
               
               
               //Update Access
               this.UpdateAccess();

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: eBay JDBC - Null pointer exception

    Your stack trace from the exception should tell you exactly where the error is occurring.
    You'll need to change the catch block to show that.
    Java Code:
    catch (Exception ex) {
        ex.printStackTrace();
    }
    You shouldn't really be catching Exception, but the specific exceptions thrown by the resources you're using (SQLException and whatever the eBay code throws). Catching all Exceptions is a bad habit to get into. You want your code to fail on an NPE, not to keep going.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Null Pointer Exception
    By jameshl2008 in forum New To Java
    Replies: 6
    Last Post: 10-22-2013, 02:56 PM
  2. null pointer exception
    By Herah in forum New To Java
    Replies: 1
    Last Post: 12-01-2011, 08:44 AM
  3. Jdbc null pointer exception
    By miko5054 in forum New To Java
    Replies: 3
    Last Post: 02-24-2011, 12:06 PM
  4. Null Pointer Exception
    By ScKaSx in forum New To Java
    Replies: 1
    Last Post: 01-24-2009, 11:27 AM
  5. Null Pointer Exception
    By Jacinth in forum New To Java
    Replies: 4
    Last Post: 01-22-2009, 01:47 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •