Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

intellij idea - 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,

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...