日期:2014-05-20 浏览次数:21156 次
create or replace procedure query_student is v_name varchar2(20); begin select name into v_name from st_t_student where id=3012; dbms_output.put_line(v_name); end query_student;
public void test(){ conn = JDBCUtils.getConnection("miniWeb", "miniWeb"); try { conn.setAutoCommit(false); //调用存储过程 cstmt = conn.prepareCall("{call query_student}"); rs = cstmt.executeQuery(); while(rs.next()){ System.out.println(rs.getString("v_name")); } conn.commit(); } catch (SQLException e) { e.printStackTrace(); try { conn.rollback(); } catch (SQLException e1) { e1.printStackTrace(); } }finally{ JDBCUtils.closeConnection(rs, pstmt, conn); } }
java.sql.SQLException: ORA-00900: invalid SQL statement at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272) at oracle.jdbc.driver.T4C8Odscrarr.receive(T4C8Odscrarr.java:203) at oracle.jdbc.driver.T4CCallableStatement.do_describe(T4CCallableStatement.java:604) at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:3037) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1861) at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1559) at com.sinosoft.javase.ProcedureTest.test(ProcedureTest.java:36) at com.sinosoft.javase.ProcedureTest.main(ProcedureTest.java:53)
create or replace procedure p_query(v_i in int,v_name out varchar2) is begin select ename into v_name from emp where empno=7900 and 1=v_i; end p_query;
------解决方案--------------------
返回结果集
create or replace package pa_query as type p_cursor is ref cursor; end pa_query; / create or replace procedure p_query(v_cursor out pa_query.p_cursor) is begin open v_cursor for select * from emp; end p_query;