错误:用户缺少未找到HSQLDB的权限或对象

时间:2016-08-24 14:49:18

标签: java database jsp jdbc hsqldb

您好我使用HSQLDB并使用属性EMPLOYEE创建了一个表ID。 db是一个独立的db,下面是它的脚本文件:

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类来访问db:

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%正确的。

1 个答案:

答案 0 :(得分:0)

您正在使用相对(基准)路径连接到数据库。此路径解析为不同执行上下文中的不同位置,例如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