简体   繁体   English

Oracle JDBC数据源-ORA-00942:表或视图不存在

[英]Oracle JDBC Datasource - ORA-00942: table or view does not exist

I have a small java console application that creates a raw jdbc connection as follows and returns it 我有一个小的Java控制台应用程序,它按如下创建原始的jdbc连接并将其返回

public static Connection createConnection(Properties props) {
    Connection conn = null;
    {
      try
      {
        Class.forName(props.getProperty("jdbcClass"));
        conn = DriverManager.getConnection(
            props.getProperty("jdbcUrl"),
            props.getProperty("username"),
            props.getProperty("password")
            );
        return conn;
      }
      catch (ClassNotFoundException e)
      {
        e.printStackTrace();
      }
      catch (SQLException e)
      {
        e.printStackTrace();
      }
    }
    return null;
}

With a properties file that looks as follows: 使用如下属性文件:

jdbcClass=oracle.jdbc.xa.client.OracleXADataSource
jdbcUrl=jdbc:oracle:thin:@stiddb01:1538:DSTD
username=*****
password=*****

I then exute a plain select * from a table and parse the results. 然后,我从表中提取出一个普通的select *并解析结果。 All this works fine up to this point. 到目前为止,所有这些工作正常。

Then I created a small jsp/jstl tomcat application with this in my context.xml file for the datasource: 然后,我在我的context.xml文件中为数据源创建了一个小型的jsp / jstl tomcat应用程序:

<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <Resource
        name="jdbc/devdb"
        auth="Container"
        type="javax.sql.DataSource"
        maxActive="100"
        maxIdle="30"
        maxWait="10000"
        username="******"
        password="******"
        driverClassName="oracle.jdbc.xa.client.OracleXADataSource"
        url="jdbc:oracle:thin:@stiddb01:1537:DSTD">
    </Resource>
</Context>

And this in my web.xml: 这在我的web.xml中:

<resource-ref>
        <description>Dev Environment</description>
        <res-ref-name>jdbc/devdb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
</resource-ref>

with the following jsp/jstl code in a jsp called query.jsp 在名为query.jsp的jsp中使用以下jsp / jstl代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<sql:query var="rs" dataSource="jdbc/devdb">
    select * from "ST_FINANCE"."STF_FINANCE_REQUEST"
</sql:query>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
</head>
<body>
    <h2>Results</h2>

    <c:forEach var="row" items="${rs.rows}">
        ${row.FINANCE_REQUEST_NO}<br />


    </c:forEach>
</body>
</html>

Then I get this error when I hit the page: 然后,当我点击页面时,我得到这个错误:

ORA-00942: table or view does not exist

Why does my console app work perfectly but the webapp bails? 为什么我的控制台应用程序可以完美运行,但Web应用程序却无法运行? Only thing I could get it to work was making the table publicly accessable on the DB but we cant have that on our production servers... 我唯一能使它工作的是使表可在数据库上公开访问,但我们不能在生产服务器上使用它。

It looks as though the two applications are accessing different databases as different users. 看起来这两个应用程序以不同的用户身份访问不同的数据库。 Try granting select privileges on ST_FINANCE.STF_FINANCE_REQUEST to user dewet1_d in the database accessed by the jsp/jstl tomcat application. 尝试向jsp / jstl tomcat应用程序访问的数据库中的用户dewet1_d授予ST_FINANCE.STF_FINANCE_REQUEST上的选择特权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM