I have simple class. Then I try to compile and run it I see ClassNotFoundException.
import java.sql.*;
public class DBProcessor{
private static String serverAd
On the command line, this
java DBProcessor
should be
java -cp .;postgresql.jar DBProcessor
And, because it includes java.sql.Driver
, when you have it working you could remove
// try {
// Class.forName("org.postgresql.Driver");
// } catch (ClassNotFoundException e) {
// System.err.println("Where is your PostgreSQL JDBC Driver? "
// + "Include in your library path!");
// e.printStackTrace();
// }
Per the DriverManager Javadoc,
The
DriverManager
methodsgetConnection
andgetDrivers
have been enhanced to support the Java Standard Edition Service Provider mechanism. JDBC 4.0 Drivers must include the fileMETA-INF/services/java.sql.Driver
. This file contains the name of the JDBC drivers implementation ofjava.sql.Driver
. For example, to load themy.sql.Driver
class, theMETA-INF/services/java.sql.Driver
file would contain the entry:my.sql.Driver
Applications no longer need to explictly load JDBC drivers using
Class.forName()
. Existing programs which currently load JDBC drivers usingClass.forName()
will continue to work without modification.