尝试在HSQLDB上运行SQL时遇到了这个异常:
java.sql.SQLSyntaxErrorException:user缺少权限或对象 发现:ADMIN at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) 在org.hsqldb.jdbc.JDBCUtil.sqlException(未知来源)at org.hsqldb.jdbc.JDBCPreparedStatement。(未知来源)at org.hsqldb.jdbc.JDBCConnection.prepareStatement(未知来源)
修改
这就是我创建Connection
对象的方式:
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName("org.hsqldb.jdbcDriver");
conn = DriverManager.getConnection("jdbc:hsqldb:mem:test://localhost","sa","");
}
catch (Exception e) {
e.printStackTrace();
}
return conn;
}
这是我所做的准备好的声明:
java.sql.PreparedStatement prSelect = con.prepareStatement("SELECT * FROM PUBLIC.ADMIN Where USERNAME=? AND PASSWORD=?;");
如何向用户授予权限?目前我正在使用SA用户。
编辑2: 这是我构建的架构 -
CREATE TABLE PUBLIC.SHOW_ORDER(
ORDER_CODE INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1),
CLIENT_ID VARCHAR(10),
NUMBER_OF_TICKETS INTEGER,
SHOW_CODE INTEGER,
CLIENT_NAME VARCHAR(25),
TOTAL_PRICE INTEGER,
PRIMARY KEY (ORDER_CODE),
);
CREATE TABLE PUBLIC.SHOW
(
CODE INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1),
MUSIC_TYPE INTEGER,
NUMBER_OF_SEATS INTEGER,
DESCRIPTION VARCHAR(100),
S_DATE DATE,
SEATS_TAKEN INTEGER,
PRIMARY KEY (CODE)
);
CREATE TABLE PUBLIC.SYS_MUSIC_TYPE (
CODE INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1),
DESCRIPTION VARCHAR(100),
PRIMARY KEY (CODE)
);
CREATE TABLE PUBLIC.ADMIN
(
USERNAME VARCHAR(25),
PASSWORD VARCHAR(25) NOT NULL,
PRIMARY KEY (USERNAME)
);
答案 0 :(得分:1)
对您最有帮助的一些DDL语句是CREATE USER,CREATE ROLE和GRANT。
这是使用指定密码创建新用户的DDL语句:
CREATE USER "CENASSIST" PASSWORD 'thepassword';
此DDL语句创建一个ROLE,可以为其分配一组权限。然后将ROLE分配给上面创建的用户:
CREATE ROLE "FRONT_END";
GRANT FRONT_END TO "CENASSIST";
此DDL块分配已创建的FRONT_END角色的权限。权限用于表访问:
GRANT SELECT, UPDATE, INSERT ON TABLE Clients TO FRONT_END;
GRANT SELECT, UPDATE, INSERT ON TABLE Rotations TO FRONT_END;
GRANT SELECT, UPDATE, INSERT ON TABLE Institutions TO FRONT_END;
GRANT SELECT, UPDATE, INSERT ON TABLE Client_MRNs TO FRONT_END;
GRANT SELECT, UPDATE, INSERT ON TABLE Payers TO FRONT_END;
HSQLDB有一本优秀的在线手册,详细介绍了用于权限和访问控制的DDL语句。