??java????oracle?洢???????
???????????? ???????[ 2014/5/27 11:42:02 ] ????????java oracle
????????????proc.getString(2)?е????2???????????????洢?????е?out?ж????????out????????λ???????proc.getString(1)????????????λ?????proc.getString(3)?????????????ж????????????????????out???????
?????????????б?
????????oracle?洢??????з?????????????з???????????out?????????????б????????????????????????????????????????????????pagkage??.??????????????
????1?? ???????????????£?
????CREATE OR REPLACE PACKAGE TESTPACKAGE AS
????TYPE Test_CURSOR IS REF CURSOR;
????end TESTPACKAGE;
????2???????洢??????洢???????
????CREATE OR REPLACE PROCEDURE TESTC(p_CURSOR out TESTPACKAGE.Test_CURSOR) IS
????BEGIN
????OPEN p_CURSOR FOR SELECT * FROM HYQ.TESTTB;
????END TESTC;
???????????????????α???????????????????????out ??????????????
??????java????????????????
package com.hyq.src;
import java.sql.*;
import java.io.OutputStream;
import java.io.Writer;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import oracle.jdbc.driver.*;
public class TestProcedureTHREE {
public TestProcedureTHREE() {
}
public static void main(String[] args ){
String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@127.0.0.1:1521:hyq";
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl?? "hyq"?? "hyq");
CallableStatement proc = null;
proc = conn.prepareCall("{ call hyq.testc(?) }");
proc.registerOutParameter(1??oracle.jdbc.OracleTypes.CURSOR);
proc.execute();
rs = (ResultSet)proc.getObject(1);
while(rs.next())
{
System.out.println("<tr><td>" + rs.getString(1) + "</td><td>"+rs.getString(2)+"</td></tr>");
}
}
catch (SQLException ex2) {
ex2.printStackTrace();
}
catch (Exception ex2) {
ex2.printStackTrace();
}
finally{
try {
if(rs != null){
rs.close();
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
}
}
}
catch (SQLException ex1) {
}
}
}
}
|
???????????????????????????oracle???????????class·????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11