I am making a program which communicated with a database via jdbc with Java. The problem is that, while in another pc the same code, having everything the same worked like a charm, now I get an error. And I can’t understand what that error means or how to fix it. I did not know in which forum to post this topic so I put it in here. If it is considered the wrong forum, feel free to move it to the apropriate one.
So here is the code, some very basic and simple code, conncting to a database made in my pc, the local host.
import java.sql.*; //import all the JDBC classes
public class Ergastirio5 {
static String[] SQL = {
"create table Department ("+
"d_id integer,"+
"d_name varchar (40),"+
"d_tel varchar(40),"+
"d_fax varchar(40) );",
"insert into Department values (1, 'Lefteris', '2100049583' ,'210948495 ');",
"insert into Department values (2, 'Kostas', '2134045673' , '210463643' );",
"insert into Department values (3, 'Takis', '2310267803' , '2310987343');",
"insert into Department values (4, 'Makis',' 2310267803' ,' 2310987343');",
"insert into Department values (5, 'Sakis',' 2310484731 ', '2310748349');",
};
public static void main(String[] args) {
String URL = "jdbc:postgresql://localhost:5432/postgres";
String username = "postgres";
String password = "mypass";
try {
Class.forName("org.postgresql.Driver");
} catch (Exception e) {
System.out.println("Failed to load JDBC/ODBC driver.");
return;
}
Statement stmt = null;
Connection con=null;
try {
con = DriverManager.getConnection (
URL,
username,
password);
stmt = con.createStatement();
} catch (Exception e) {
System.err.println("problems connecting to "+URL);
}
try {
// execute SQL commands to create table, insert data
for (int i=0; i<SQL.length; i++) {
stmt.execute(SQL[i]);
}
con.close();
} catch (Exception e) {
System.err.println("problems with SQL sent to "+URL+
": "+e.getMessage());
}
}
}
That’s it. And the error is:
Exception in thread “main” java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at Ergastirio5.main(Ergastirio5.java:48)
Java Result: 1
I haven’t posted in this forum for ages but if there is something I remember about the forum is that I always got help here, so please anyone got any clue as to what might be the problem here?
Thanks in advance.
, hoping to get some more replies and get this problem behind me :-\