0

我在本地安装的 Oracle 数据库中创建了下表:-

CREATE TABLE "SYSTEM"."WAREHOUSES" 
   (    "WAREHOUSE_ID" NUMBER NOT NULL ENABLE, 
    "WAREHOUSE_SPEC" CLOB, 
     CONSTRAINT "WAREHOUSES_PK" PRIMARY KEY ("WAREHOUSE_ID");

它为 4 行,主键为 1、2、3 和 4。

现在我编写了以下 Java 代码来访问“WAREHOUSE_SPEC”列(其中包含每一行的 XML 文件):-

import oracle.xml.xquery.xqjdb.OXQDDataSource;

import javax.xml.xquery.XQItemType;
import javax.xml.xquery.XQResultSequence;
import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQPreparedExpression;
import javax.xml.namespace.QName;

public class AccessData
{
    public static void main(String argv[])
    {
        try
        {
            OXQDDataSource oxqDS = new OXQDDataSource();
            oxqDS.setProperty("driver", "jdbc:oracle:thin");
            oxqDS.setProperty("dbusername", "SYSTEM");
            oxqDS.setProperty("dbpassword", "PWD");
            oxqDS.setProperty("dbserver", "localhost");
            oxqDS.setProperty("dbport", "1521");
            oxqDS.setProperty("serviceName", "xe");
            XQConnection conn = oxqDS.getConnection();
            XQItemType  itemTypeInt = conn.createAtomicType(XQItemType.XQBASETYPE_INT);
            XQPreparedExpression expr = conn.prepareExpression("declare variable $x as xs:int external; for $i in fn:collection('oradb:/mydb/WAREHOUSES') where $i/ROW/WAREHOUSE_ID < $x return $i/ROW/WAREHOUSE_SPEC/Warehouse");
            expr.bindInt(new QName("x"), 3, itemTypeInt);
            XQResultSequence xqSeq = expr.executeQuery();
            while (xqSeq.next()) {
                System.out.println(1);
                System.out.println (xqSeq.getItemAsString(null));
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

这里,“mydb”是数据库模式,“WAREHOUSES”是表名。

该代码应返回 2 行,主键为 1 和 2,但它无法找到该表,并给出以下错误:-

javax.xml.xquery.XQException: java.sql.SQLException: ORA-00942: table or view does not exist

    at oracle.xml.xquery.xqjimpl.OXQDSequence.next(OXQDSequence.java:421)
    at example1.main(AccessData.java:33)
Caused by: java.lang.RuntimeException: java.sql.SQLException: ORA-00942: table or view does not exist

    at oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.OXQDXDBConnExpr.prepare(OXQDXDBConnExpr.java:367)
    at oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.OXQDXDBConnExpr.access$000(OXQDXDBConnExpr.java:102)
    at oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.OXQDXDBConnExpr$XDBConnIterator.Restart(OXQDXDBConnExpr.java:808)
    at oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.OXQDXQuerySequence.next(OXQDXQuerySequence.java:127)
    at oracle.xml.xquery.xqjimpl.OXQDSequence.next(OXQDSequence.java:386)
    ... 1 more
Caused by: java.sql.SQLException: ORA-00942: table or view does not exist

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:219)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:813)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1049)
    at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:854)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1154)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3370)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3415)
    at oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.OXQDXDBConnExpr.prepare(OXQDXDBConnExpr.java:351)
    ... 5 more

我在这里做错什么了吗?

4

0 回答 0