Swears that the database does not exist. Indeed, dbConnection for some reason remains null .
public class CreatingConnection { private static Connection getDBConnection() { Connection dbConnection = null; try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { System.out.println(e.getMessage()); } try { dbConnection = DriverManager.getConnection("jdbc:postgresql::port/db","postgres", "user"); return dbConnection; } catch (SQLException e) { System.out.println(e.getMessage()); } return dbConnection; } static void createDbUserTable() throws SQLException { Connection dbConnection = null; Statement statement = null; String createTableSQL = "CREATE TABLE DBUSER(" + "USER_ID NUMBER(5) NOT NULL, " + "USERNAME VARCHAR(20) NOT NULL, " + "MESSAGE VARCHAR(20) NOT NULL, " + ")"; try { dbConnection = getDBConnection(); System.out.println(dbConnection); statement = dbConnection.createStatement(); statement.execute(createTableSQL); System.out.println("Table \"dbuser\" is created!"); } catch (SQLException e) { System.out.println(e.getMessage()); } finally { if (statement != null) { statement.close(); } if (dbConnection != null) { dbConnection.close(); } } } }
:postgresql::port/dbhere is an error. specify the correct data. postgresql is the address of the base where it lies, port is the port (number), db is the name of the schema (base) - Senior Pomidor