I went around the Internet for this question and I just can't figure it out.
I am developing a Java Application on Netbeans and I'm connecting to the H2 Database Engine through Netbeans IDE. I am not interested in using the console.
The code to connect to H2 is as follows (from the client side):
Connection connt = null;
String url = "jdbc:h2:tcp://" + SERVER_IP + ":" + SERVER_PORT + "//C:/Databases/businessApp;";
connt = DriverManager.getConnection(url, "sa", "");
When the code reaches the .getConnection()
method, it stays there and does nothing. I am almost sure that there is something wrong with the URL syntax.
SERVER_IP
and SERVER_PORT
are defined earlier and are not null.
I think semi colon(;) after "businessApp" is the culprit. Try after removing it.
I think the culpript is your final connection string which looks like
"jdbc:h2:tcp://192.168.1.154:8080//C:/Databases/businessApp"
and h2 apparently doesn't recognize UNC paths.
The above under GNU/Linux instead would work because of the different convention used for paths:
"jdbc:h2:tcp://192.168.1.154:8080/home/user/Databases/businessApp"
The solution I found is to add a slash after the port number, your string would thus become:
"jdbc:h2:tcp://192.168.1.154:8080/C:/Databases/businessApp"
this works both in Linux and Windows
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.