• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Runtime - NullPointerException

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not quite sure where to start
but I will do my best to not have it turn into ramble.

First I want to check for an "old" open DB connection
and close it if there is one open


Now where my error occurs:
Then in the while (connected == false)
loop, I delete all of the data out of the tables
because I do not want stale data appearing on the GUI.
For some reason this is where is throws my error.

If I take them out it runs fine.
The real strange deal is I have another program
set up to read from a processor the same way
and that one throws no errors at all.
So I am thinking (okay hoping) its just something small I am missing

Thank you very much for all of your time
January

 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The variable "psDELtblRtFields" is null until the statement

psDELtblRtFields = conn.prepareStatement(DELETE_tblRtFields);

is executed. But your call to "psDELtblRtFields.executeQuery()" occurs a few dozen lines earlier in your program than does the prepareStatement call, so the first time that executeQuery() is called, psDELtblRtFields is null and you get a NullPointerException. Makes sense, right?

You might simply enhance that "while (connected == false)" to include a "conn == null", as well. But you're really going to have to manage things a bit more carefully. The PreparedStatements are in static variables, but the Connection is in a member variable; and you're re-opening the database connection without ever closing the old connection, or closing the PreparedStatements, or anything.
 
January Montague
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But your call to "psDELtblRtFields.executeQuery()" occurs a few dozen lines earlier in your program than does the prepareStatement call, so the first time that executeQuery() is called, psDELtblRtFields is null and you get a NullPointerException. Makes sense, right?


Ya for sure.
That is kinda what I thought,
the only real confusing part is I have anohter
program doing the same thing, but connected to a different processor.

I will work with your advice for
now and see how far I can get.
I am new to JDBC and still learning as I go along.

Thank you for your reply
and when I get this bugger figured out
I will post another reply

Any other advice would be awesome
if anything else comes to mind.

Thanx
January
 
Fire me boy! Cool, soothing, shameless self promotion:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic