英文:
How close possibility to add new data in H2?
问题
在向数据库添加一些数据后,我需要将整个数据库设置为只读模式。如何使用h2嵌入式数据库和驱动程序管理器(jdbc)来实现这一点最简单?
Class.forName("org.h2.Driver").newInstance();
con = DriverManager.getConnection("jdbc:h2:" + "./"+dbName, "hereIsUser", "hereIsPassword");
如果需要更多帮助,请告诉我。
英文:
I have a problem. After adding some data to database, I need to set read-only mode for whole DB. What is the easiest way to do that using h2 embedded DB with driver manager (jdbc)?
Class.forName("org.h2.Driver").newInstance();
con = DriverManager.getConnection("jdbc:h2:" + "./"+dbName, "hereIsUser", "hereIsPassword");
答案1
得分: 1
-
通过在JDBC URL后附加
;ACCESS_MODE_DATA=r
(在您的情况下为"jdbc:h2:" + "./" + dbName + ";ACCESS_MODE_DATA=r"
),您可以以只读模式打开整个数据库。 -
您可以创建一个单独的用户(
CREATE USER userName PASSWORD 'some_password'
),并只赋予他SELECT
权限(GRANT SELECT ON SCHEMA nameOfYourSchema TO userName
),然后使用该用户。
英文:
-
You can open the whole database in read-only mode by appending
;ACCESS_MODE_DATA=r
to the JDBC URL ("jdbc:h2:" + "./" + dbName + ";ACCESS_MODE_DATA=r"
in your case. -
You can create a separate user (
CREATE USER userName PASSWORD 'some_password'
) and give it only theSELECT
grants (GRANT SELECT ON SCHEMA nameOfYourSchema TO userName
) and use that user.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论