gpt4 book ai didi

java - 错误: User lacks privilege or object not found HSQLDB

转载 作者:太空宇宙 更新时间:2023-11-04 12:18:23 24 4
gpt4 key购买 nike

您好,我正在使用 HSQLDB 并创建了一个带有属性 ID 的表 EMPLOYEE。该数据库是一个独立的数据库,这里是它的脚本文件:

SET DATABASE UNIQUE NAME HSQLDB56BCF1778F
SET DATABASE GC 0
SET DATABASE DEFAULT RESULT MEMORY ROWS 0
SET DATABASE EVENT LOG LEVEL 0
SET DATABASE TRANSACTION CONTROL LOCKS
SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED
SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE
SET DATABASE TEXT TABLE DEFAULTS ''
SET DATABASE SQL NAMES FALSE
SET DATABASE SQL REFERENCES FALSE
SET DATABASE SQL SIZE TRUE
SET DATABASE SQL TYPES FALSE
SET DATABASE SQL TDC DELETE TRUE
SET DATABASE SQL TDC UPDATE TRUE
SET DATABASE SQL TRANSLATE TTI TYPES TRUE
SET DATABASE SQL TRANSLATE TTI TYPES TRUE
SET DATABASE SQL CONCAT NULLS TRUE
SET DATABASE SQL UNIQUE NULLS TRUE
SET DATABASE SQL CONVERT TRUNCATE TRUE
SET DATABASE SQL AVG SCALE 0
SET DATABASE SQL DOUBLE NAN TRUE
SET FILES WRITE DELAY 500 MILLIS
SET FILES BACKUP INCREMENT TRUE
SET FILES CACHE SIZE 10000
SET FILES CACHE ROWS 50000
SET FILES SCALE 32
SET FILES LOB SCALE 32
SET FILES DEFRAG 0
SET FILES NIO TRUE
SET FILES NIO SIZE 256
SET FILES LOG TRUE
SET FILES LOG SIZE 50
CREATE USER "Chris" PASSWORD DIGEST '4a7d1ed414474e4033ac29ccb8653d9b'
ALTER USER "Chris" SET LOCAL TRUE
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
SET SCHEMA PUBLIC
CREATE MEMORY TABLE PUBLIC.EMPLOYEE(ID VARCHAR(20))
ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1
SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC
GRANT DBA TO "Chris"
SET SCHEMA SYSTEM_LOBS
INSERT INTO BLOCKS VALUES(0,2147483647,0)
SET SCHEMA PUBLIC
INSERT INTO EMPLOYEE VALUES('CHRIS')

我使用这个java类来访问数据库:

package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
* Dies Klasse liefert eine JDBC Connection zurück
* @author Christian
*
*/
public class JDBCConnector {

private Connection connection;

public JDBCConnector(String url, String user, String password){
try{
Class.forName("org.hsqldb.jdbcDriver");
connection = DriverManager.getConnection(url, user, password);
if(connection != null){
System.out.println("Verbindung hergestellt");
}
}catch ( ClassNotFoundException e ){
System.err.println("Der Datenbanktreiber konnte nicht geladen werden");
e.printStackTrace();
} catch (SQLException e) {
System.err.println("Beim Erstellen der Verbindung ist ein Feheler aufgetreten.\n"
+ "Bitte überprüfen Sie die URL, sowie Usernamen und Passwort");
}
}

public Connection getConnection() throws Exception{
if(connection != null){
return connection;
}else{
throw new Exception("Connection == null");
}
}

public String getFirstEntry(){
try {
Statement stmt;
ResultSet rs = null;
stmt = connection.createStatement();
rs = stmt.executeQuery("SELECT * FROM EMPLOYEE;");
rs.next();
String s = rs.getString(1);
connection.close();
return s;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return "";
}


}

这只是一个测试类,所以......

这里我从 jsp 文件调用该函数:

<% JDBCConnector connector = new JDBCConnector("jdbc:hsqldb:file:/Gefaehrdungsbeurteilung_Full/WebContent/gefaehrdungsbeurteilung_full/server/db/DB2;shutdown=true", "Chris", "0000"); 
out.append(connector.getFirstEntry());
%>

有人有解决办法吗?过去发生此错误是因为我忘记了 shutdown=true 但这次,我不知道...表名 100% 正确。

最佳答案

您正在使用相对(基)路径连接到数据库。该路径解析为不同执行上下文(例如 JSP)中的不同位置。

在开发过程中,使用 ifexists=true 连接属性以避免创建和连接到新数据库。将路径指向的现有数据库放入执行上下文中。

<% JDBCConnector connector = new JDBCConnector("jdbc:hsqldb:file:/Gefaehrdungsbeurteilung_Full/WebContent/gefaehrdungsbeurteilung_full/server/db/DB2;shutdown=true;ifexists=true", "Chris", "0000"); 
out.append(connector.getFirstEntry());
%>

shutdown=true 属性对于测试很有用。如果您的连接持续很长时间,那么也适合生产。但是,如果您定期关闭连接,则会反复关闭数据库。在这种情况下,您可以考虑替代方案,hsqldb.write_delay=false。请参阅指南:

http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html#dpc_connection_props

http://hsqldb.org/doc/2.0/guide/management-chapt.html#mtc_cache_persistence

关于java - 错误: User lacks privilege or object not found HSQLDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39126605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com