• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Runtime - NullPointerException

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic