Error is: java: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown
and occurs at this: Class.forName("org.postgresql.Driver");
Most of the time, it was weird maven formatting or the such, but I think I have it right (copy pasted). Here is the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Database-Test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1203-jdbc4</version>
</dependency>
</dependencies>
</project>
If needed, here is the file path
and the main class
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.*;
public class DBTEST{
public static void main (String[]args) throws SQLException, URISyntaxException{
System.out.println(getConnection());
}
private static Connection getConnection() throws URISyntaxException, SQLException{
Class.forName("org.postgresql.Driver");
//String dbUrl = System.getenv("DATABASE_URL");
String dbUrl = "postgres://fxeymwfokhsimv:bd5c9975533c20ed3ab4df7c0ea263911207854c2cac46983fafce18689a1161@ec2-184-72-162-198.compute-1.amazonaws.com:5432/dlfvrduvj5qcr";
return DriverManager.getConnection(dbUrl);
}
}
DB Host and Database
Don't worry about me sharing my database credentials - this is a test project and is just for me to figure out how to use it.