Oracle存储过程

陕K流年 2006-04-20 09:22:13


<%@ page contentType="text/html; charset=GBK" import="java.sql.*,javax.naming.*,javax.sql.*,oracle.jdbc.driver.*"%>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<h1>
<%

try {
Context initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
CallableStatement stmt = conn.prepareCall("{call getEmp(?)}");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.execute();
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
out.println(rs.getString(1) + "\t" + rs.getString(2) + "<br>");
}
rs.close();
stmt.close();
conn.close();
}
catch (Exception ex) {
out.println(ex);
}
%>
</h1>
</body>
</html>

页面回抛出

java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列: PLS-00201: 必须说明标识符 'GETEMP' ORA-06550: 第 1 行, 第 7 列: PL/SQL: Statement ignored
...全文
229 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
陕K流年 2006-04-22
  • 打赏
  • 举报
回复
create or replace package pkg
is
type cur is ref cursor;
end;

create or replace procedure getemp(strSql in String,cur out pkg.cur)
is
exec_str varchar2(32767);
begin
exec_str := strSql;
open cur for exec_str;
end;


JSP代码:
<%@ page contentType="text/html; charset=GBK" import="java.sql.*,javax.naming.*,javax.sql.*,oracle.jdbc.driver.*"%>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<h1>
<%

try {
Context initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
CallableStatement stmt = conn.prepareCall("{call getEmp(?,?)}");
stmt.setString(1,"select eid,ename from emp");
stmt.registerOutParameter(2,OracleTypes.CURSOR);
stmt.execute();
ResultSet rs = (ResultSet)stmt.getObject(2);
while (rs.next()) {
out.println(rs.getString(1) + "\t" + rs.getString(2) + "<br/>");
}
rs.close();
stmt.close();
conn.close();
}
catch (Exception ex) {
out.println(ex);
}
%>
</h1>
</body>
</html>



自己解决了!!

陕K流年 2006-04-21
  • 打赏
  • 举报
回复
没看明白不要乱说!!
sgdb 2006-04-21
  • 打赏
  • 举报
回复
package不是那么写的。
create or replace package pkg
as
type cur is ref cursor;

procedure getemp(strSql in String,cur out pkg.cur);
end;
jiejienihao 2006-04-21
  • 打赏
  • 举报
回复
jsp的潜水者,还不是很精通,所以静观其变,快!大家顶啊 !!!!!!!!!!!
qingzhuang 2006-04-20
  • 打赏
  • 举报
回复
你需要在数据库中写GETEMP的储存过程,并定义GETEMP
陕K流年 2006-04-20
  • 打赏
  • 举报
回复
急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
陕K流年 2006-04-20
  • 打赏
  • 举报
回复
我的代码:

create or replace package pkg
is
type cur is ref cursor;
end;

create or replace procedure getemp(strSql in String,cur out pkg.cur)
is
begin
open cur for strSql;
end;
end;

JSP代码:
<%@ page contentType="text/html; charset=GBK" import="java.sql.*,javax.naming.*,javax.sql.*,oracle.jdbc.driver.*"%>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<h1>
<%

try {
Context initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
CallableStatement stmt = conn.prepareCall("{call getEmp(?,?)}");
stmt.setString(1,"select eid,ename from emp");
stmt.registerOutParameter(2,OracleTypes.CURSOR);
stmt.execute();
ResultSet rs = stmt.getObject(1);
while (rs.next()) {
out.println(rs.getString(1) + "\t" + rs.getString(2) + "<br>");
}
rs.close();
stmt.close();
conn.close();
}
catch (Exception ex) {
out.println(ex);
}
%>
</h1>
</body>
</html>

异常:

java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列: PLS-00201: 必须说明标识符 'GETEMP' ORA-06550: 第 1 行, 第 7 列: PL/SQL: Statement ignored

sgdb 2006-04-20
  • 打赏
  • 举报
回复
呵呵,要得到oracle的存储过程结果集没这么简单的,需要把PROCEDURE 装到package里,然后通过CURSOR来得到结果集
陕K流年 2006-04-20
  • 打赏
  • 举报
回复
已经写了!!!

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧