错误代码:
IO Exception: "java.nio.file.FileSystemException: /Users/Franco/Desktop/h2: Operation not permitted"; "/Users/Franco/Desktop/h2"
IO Exception: "java.nio.file.FileSystemException: /Users/Franco/Desktop/h2: Operation not permitted"; "/Users/Franco/Desktop/h2" [90031-212] 90031/90031])
Screenshot
IDE中的代码:
import java.sql.*;
public class Main {
public static void main(String[] args) throws Exception{
Class.forName("org.h2.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:h2:"+ "/Users/Franco/Desktop/h2/bin", "root", "myPassword");
Statement stmt = con.createStatement();
//Código para crear una tabla. Elimina la tabla si esta ya existe y la
//vuelve a crear
String createSql = """
DROP TABLE IF EXISTS TEST;
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
INSERT INTO TEST VALUES(1, 'Hello');
INSERT INTO TEST VALUES(2, 'World');
""";
stmt.execute(createSql);
//Codigo para consultar todos los registros de la tabla TEST
String sql = "select * from TEST";
ResultSet rd = stmt.executeQuery(sql);
//Código para recorrer el resultado de la consulta
while(rd.next()) {
System.out.println(rd.getInt(1) + rd.getString(2));
}
con.close();
}
}
我想可能是访问请求,我有一台MacOS Ventura 13. 2. 1的Mac
3条答案
按热度按时间tquggr8v1#
我认为问题出在您的JDBC连接字符串中(缺少
file:
),请尝试:它可能还需要驱动器,例如C:
C:/用户/Franco/桌面/h2/bin是否存在?
oaxa6hgo2#
我在site中做了一些类似的代码
连接c = drm.getConnection(“jdbc:h2:文件:“+“/binlbr”,“管理员”,“通过”);
而且成功了!
r6l8ljro3#
解决办法是: