• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime - NullPointerException

 
January Montague
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

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic