Answer the question
In order to leave comments, you need to log in
JDBC application won't start, why?
Hello!
Finished learning the basics of java, decided to move on with JDBC. I began to create a simple connection to Postgresql according to the video lesson (in my opinion, it’s easier than a steamed turnip) I work through Eclipse. But then I get an error that I can't figure out how to solve:
Exception in thread "main" java.lang.SecurityException: Prohibited package name: java
at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:898)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1014)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at java.base/sun.launcher.LauncherHelper.loadMainClass(LauncherHelper.java:760)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:655)
package java;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Contest {
static final String ur = "jdbc:postgresql://127.0.0.1:5432/postgres";
static final String log = "postgres";
static final String pas = "lll";
public static void main (String [] args ) {
System.out.println("Testing connection to PostgreSQL JDBC");
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
System.out.println("PostgreSQL JDBC Driver is not found. Include it in your library path ");
e.printStackTrace();
return;
}
System.out.println("PostgreSQL JDBC Driver successfully connected");
Connection connection = null;
try {
connection = DriverManager.getConnection(ur, log, pas);
} catch (SQLException e) {
System.out.println("Connection Failed");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You successfully connected to database now");
} else {
System.out.println("Failed to make connection to database");
}
}
}
Answer the question
In order to leave comments, you need to log in
Failed to paste "Prohibited package name: java" into https://translate.google.com ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question