多接近在H2中添加新数据的可能性?

huangapple go评论82阅读模式
英文:

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

  1. 通过在JDBC URL后附加;ACCESS_MODE_DATA=r(在您的情况下为"jdbc:h2:" + "./" + dbName + ";ACCESS_MODE_DATA=r"),您可以以只读模式打开整个数据库。

  2. 您可以创建一个单独的用户(CREATE USER userName PASSWORD 'some_password'),并只赋予他SELECT权限(GRANT SELECT ON SCHEMA nameOfYourSchema TO userName),然后使用该用户。

英文:
  1. 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.

  2. You can create a separate user (CREATE USER userName PASSWORD 'some_password') and give it only the SELECT grants (GRANT SELECT ON SCHEMA nameOfYourSchema TO userName) and use that user.

huangapple
  • 本文由 发表于 2020年8月25日 19:57:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63578365.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定