I was trying to run the following code and am getting this error:
Exception in thread "main" java.lang.NullPointerException
Here is the code:
The error is pointing to the line:
What could be causing this problem? Is the satic declaration of DataSource the problem? but unless I decalre it as static I dont think I can access it from the main method. I hope someone can advise. Thanks.
I appreciate the reply. I am using glassfish as the appserver. Datasource has already been set up. The database is MySQL, the IDE I am using is NetBeans. The code I posted was part of a web app. I was actually testing this particular piece of code seperately to see if I can use this bean to write to the table. The Servlets in this webapp dont seem to have any problem writing to the table in the database. I am not sure what else to do...