你需要在数据库中写GETEMP的储存过程,并定义GETEMP
解决方案 »
- jboss 不显示 info [schemaUpdate]
- 利用myeclipse编辑.xml文件时一直报URI has an authority compon
- 不用编辑器,看看下面代码能不能同步编译,如果可以,结果是什么?
- TOMCAT关闭时候,数据库连接未释放
- 关于Spring AOP的问题
- 请问将struts和jboss整合时,要不要将struts的相关包拷由到jboss下面,还是直接将编译好war发布到jobss的deploy下就就可以了?谢谢。
- Hibername关于MYSQL的问题?
- 用JBuilder还是用Ecllipse???
- Hibernate问题
- 大婶们,小弟求教一个关于多线程的问题啊
- 请教package外部类的使用方法
- 在武汉工作的或者曾经在武汉工作过的大虾进来看看 ~~~~
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
create or replace package pkg
as
type cur is ref cursor;procedure getemp(strSql in String,cur out pkg.cur);
end;
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>自己解决了!!