I have simple class. Then I try to compile and run it I see ClassNotFoundException.
import java.sql.*;
public class DBProcessor{
private static String serverAdres = "127.0.0.1:5432";
private static String DBname = "dota";
private static String clientName = "postgres";
private static String password = "master";
private static Connection connection;
public static void connect() {
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();
}
try {
connection = DriverManager.getConnection("jdbc:postgresql://" + serverAdres + "/" + DBname, clientName, password);
} catch (SQLException e) {
System.err.println("Connection Failed! Check output console");
e.printStackTrace();
}
if (connection == null) {
System.err.println("Failed to make connection!");
}
}
public static void main(String[] args){
DBProcessor db = new DBProcessor();
db.connect();
}
}
I'm using Windows cmd:
C:\rmi2>javac -classpath postgresql.jar DBProcessor.java
C:\rmi2>java DBProcessor
Where is your PostgreSQL JDBC Driver? Include in your library path!
java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at DBProcessor.connect(DBProcessor.java:12)
at DBProcessor.main(DBProcessor.java:34)
Connection Failed! Check output console
java.sql.SQLException: No suitable driver found for jdbc:postgresql://127.0.0.1:
5432/dota
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DBProcessor.connect(DBProcessor.java:20)
at DBProcessor.main(DBProcessor.java:34)
Failed to make connection!
What I'm doing wrong? So, this is postgrsql library https://www.dropbox.com/s/idx5l0kub5rn1b8/postgresql.jar?dl=0