【发布时间】:2012-04-16 01:18:26
【问题描述】:
我有一个小型 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;
}
使用如下所示的属性文件:
jdbcClass=oracle.jdbc.xa.client.OracleXADataSource
jdbcUrl=jdbc:oracle:thin:@stiddb01:1538:DSTD
username=*****
password=*****
然后我从表中执行一个普通的 select * 并解析结果。到目前为止,这一切都很好。
然后我在我的 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>
这在我的 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>
在名为 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>
然后我在点击页面时收到此错误:
ORA-00942: table or view does not exist
为什么我的控制台应用程序可以完美运行,但 web 应用程序却无法运行? 我唯一能让它工作的就是让该表在数据库上可公开访问,但我们不能在我们的生产服务器上拥有它......
【问题讨论】:
-
不太清楚您所说的可公开访问是什么意思。能详细点吗?
-
您的 Java 控制台应用程序是否应该访问与 jsp/jstl tomcat 应用程序相同的数据库?两个应用程序中的 URL 和用户名/密码似乎都不同。
标签: sql oracle jdbc datasource