• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException when trying to connect to MySQL Database

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am trying to insert values from a .csv file into a MySQL database from a GUI. I cannot seem to accomplish this. I keep getting a null pointer exception where I set the connection properties in my main method. I also cannot seem to figure out how to use the importData() method after setting my variables in my GUI. I currently have that method called in the main method. I would appreciate any help anyone can give me. Thank you. Here is my code:

 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the detailed stack trace of the exception? That might help to figure out whats wrong.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If an exception is been thrown in your connect() method you're completely ignoring the exception, only printing the trace and returning null.

That is indeed asking for trouble. The returned connection should in no way be null. You know, if you invoke/access some object reference which is actually null, you'll see NullPointerExceptions flying around. And that would happen when you call Connection#createStatement().

(didn't you notice the printed trace from connect() by the way?)
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic