一. 创建表并插入数据
SQL> create table tb_do_only(
2 id number primary key,
3 name varchar2(10)
4 );
Table created.
SQL> commit;
Commit complete.
SQL> insert into tb_do_only values(1001, 'tom');
1 row created.
SQL> insert into tb_do_only values(1002, 'tony');
1 row created.
SQL> insert into tb_do_only values(1003, 'david');
1 row created.
SQL> insert into tb_do_only values(1004, 'jack');
1 row created.
SQL> commit;
Commit complete.
二. 创建返回单值存储
SQL> create or replace procedure pro_return_nonlist(v1 in number, v2 out varchar2)
2 as
3 begin
4 select name into v2 from tb_do_only where id=v1;
5 end pro_return_nonlist;
6 /
Procedure created.
SQL> commit;
Commit complete.
三.创建非返回相应测试Java类
package return_non_list;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
public class Query_non_list {
public static void main(String[] args) {
String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "scott", "tiger");
CallableStatement proc = null;
proc = conn.prepareCall("{ call scott.pro_return_nonlist(?,?) }");
proc.setInt(1, 1003);
proc.registerOutParameter(2, Types.VARCHAR);
proc.execute();
String testPrint = proc.getString(2);
System.out.println("the query result is: " + testPrint);
} 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) {
}
}
}
}