Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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,

question from:https://stackoverflow.com/questions/65876757/cannot-invoke-java-sql-connection-getmetadata-because-parameter2-is-null

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

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:/..."


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...