Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot invoke "java.sql.Connection.getMetaData()" because "<parameter2>" is null

Hi I am using an H2 database for a tutorial I am following online.

I downloaded the H2 database jar file and put it in a lib file like so:

Click here

I also created a library in my project structure like so:

Click here

Main code to test:

public class Main {

    public static void main(String[] args) throws SQLException {
    // write your code here
        Server.main();
        System.out.println("DB Launched");
    }
}

Then I created a db folder - and when I ran my application I entered the path to the DB folder in my project solution for the 'JDBC url'. I followed all of the instructions for the course.

Then when I connected I got the following error (in the web application):

See error

Cannot invoke "java.sql.Connection.getMetaData()" because "<parameter2>" is null
java.lang.NullPointerException: Cannot invoke "java.sql.Connection.getMetaData()" because "<parameter2>" is null
    at org.h2.bnf.context.DbContents.readContents(DbContents.java:154)
    at org.h2.server.web.WebApp.tables(WebApp.java:698)
    at org.h2.server.web.WebApp.process(WebApp.java:225)
    at org.h2.server.web.WebApp.processRequest(WebApp.java:170)
    at org.h2.server.web.WebThread.process(WebThread.java:134)
    at org.h2.server.web.WebThread.run(WebThread.java:90)
    at java.base/java.lang.Thread.run(Thread.java:832)

I followed all instructions... I do not know why I am getting this error - I don't know what I'm doing wrong.

Thank you,

tomkt,

like image 372
tomtomkt Avatar asked Jun 14 '26 03:06

tomtomkt


2 Answers

Because in the class they ask you to paste in the file name to the JDBC file on the H2 console, but he doesn't show that you need to leave the front items...

So it should be jdbc:h2:C:\your file path

If you are missing the jdbc:h2 at the front of the field it fails with the message you have above enter image description here

like image 151
StandardBloke Avatar answered Jun 17 '26 01:06

StandardBloke


Do not delete the "jdbc:h2:" at the beginning. I was following the same course and found my problem. Just replace the ~/test part. So it should look something like "jdbc:h2:D:/..."

like image 25
Zodius05 Avatar answered Jun 17 '26 03:06

Zodius05