Class not found :-com.mysql.jdbc.Driver
Exception in thread "main" java.lang.NullPointerException at Retail.DBConnection.selectRecords(DBConnection.java:80)
Now my question is i have set CLASSPATH setting for java.sql package in bash.bashrc file in ubuntu and i am providing another classpath at command line invocation .Will it override my system CLASSPATH because it works perfectly if i remove this jar files and then run like simple program..
When you use the -cp or -classpath switch on the command line, the CLASSPATH environment variable will be ignored. Java will not automatically use what you put on the command line and the CLASSPATH environment variable both at the same time.
When you use the -jar switch to run your program as an executable JAR, then the CLASSPATH environment variable will be ignored, and also the -cp and -classpath switches will be ignored. The place to set your classpath in that case is in the META-INF/MANIFEST.MF file (using the Class-Path attribute).
So, it does not work if you put the JDBC driver in the CLASSPATH environment variable, but also use the -cp switch on the command line. Put the JDBC driver also in the path that you use after the -cp switch.
Setting CLASSPATH or using -cp or -classpath on the command line when you also use the -jar switch will also not work.
I would recommend you not to use the classpath environment variable because:
If you are working on multiple projects at the same time you'll have you alter it every time you switch projects.
If you want to run 2 programs which both use the variable at the same time you'll have to create 2 different session in which they run.
And it's not really portable (often you need administrator rights to set that variable).
Its worth noticing that how you run your program finally i.e. by using -jar switch or simply with providing classname as suggested by "Jesper de Jong" that in case of -jar option CLASSPATH environment variable and -cp option will be ignored and classpath defined in the Manifest file will be take over.