0

Currently I try to connect locally to my mysql Server. My code for it looks the following:

import java.sql.*; 

public class JdbcSelectTest {
    public static void main(String[] args) {
        try (
                Connection conn = DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/ebookshop?useSSL=false", "...", "...");

                Statement stmt = conn.createStatement();
        ) {
            String strSelect = "select title, price, qty from books";
            System.out.println("The SQL query is: " + strSelect);
            System.out.println();

            ResultSet rset = stmt.executeQuery(strSelect);

            System.out.println("The records selected are:");
            int rowCount = 0;
            while(rset.next()) {   // Move the cursor to the next row, return false if no more row
                String title = rset.getString("title");
                double price = rset.getDouble("price");
                int    qty   = rset.getInt("qty");
                System.out.println(title + ", " + price + ", " + qty);
                ++rowCount;
            }
            System.out.println("Total number of records = " + rowCount);

        } catch(SQLException ex) {
            ex.printStackTrace();
        }
    }
}

Now when I compile with: javac JdbcSelectTest.java everything works fine. But now when I try to run the Compilation with: java -cp .;C:\Users\Marco\IdeaProjects\mysql-connector-java-8.0.13\mysql-connector-java-8.0.13.jar JdbcSelectTest I get this following error:

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: JdbcSelectTest has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0...

My JAVA_HOME property points to my locally installed jdk version 11.0.1.
The mysql-connector-java version ist: 8.0.13.
Can anyone help me out - btw. Im pretty newbie on java -so any comment helps.

2 Answers 2

4

Your issue is not related to the mysql lib.

The meaningful parts of the errormessage:

JdbcSelectTest has been **compiled by** [...] Java Runtime (class file version **55.0**)

vs

this [...] Java Runtime only **recognizes** class file versions up to **52.0**

This can be translated to something like:

JdbcSelectTest has been compiled by Java 11, but was attempted to run by Java 8.

If you want to verify this, just type the following these commands into your console:

:~ > java -version
:~ > javac -version

And you will seem them being different. You have already checked your JAVA_HOME variable, but you must also need take a look at your PATH variable to have this fixed. This link will help you with that.

Sign up to request clarification or add additional context in comments.

Comments

2

There is a java version mismatch. You need to install proper version of java, i.e. java 8 and compile you code with it. Here you can find a table with versions required: vers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.