一. 创建表并插入数据
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_doi(v1 in number, v2 in varchar2) -- in 表示输入参数
2 as
3
4 begin
5 insert into tb_do_only values(v1, v2);
6 end pro_doi;
7 /
Procedure created.
SQL> commit;
Commit complete.
三.创建非返回相应测试Java类
package do_only;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Insert {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
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;
CallableStatement cstmt = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "scott", "tiger");
CallableStatement proc = null;
proc = conn.prepareCall("{ call scott.pro_doi(?,?) }"); //invoke procedure
proc.setInt(1, 1008);
proc.setString(2, "kerry");
proc.execute();
conn.commit();
} 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) {
}
}
}
}
四. 查询库进行验证
SQL> select * from tb_do_only;
ID NAME
---------- ----------
1001 tom
1002 tony
1003 david
1004 jack
4 rows selected.
SQL>
SQL> /
ID NAME
---------- ----------
1001 tom
1002 tony
1003 david
1004 jack
1005 kerry
5 rows selected.