oracle学习笔记14--PLSQL1
pl/sql编程实例:
1.只包括执行部分的pl/sql块
set serveroutput on;打开输出选项
package morflame;import java.sql.*;public class TestOraPro1 {public static void main(String[] args) {// TODO Auto-generated method stubString driver="oracle.jdbc.driver.OracleDriver";String dburl="jdbc:oracle:thin:@localhost:1521:orcl";String dbuser="scott";String dbpass="tiger";Connection conn=null;Statement stmt=null;ResultSet rs=null;CallableStatement cs=null;//准备CallableStatement对象来调用过程try {Class.forName(driver);conn=DriverManager.getConnection(dburl,dbuser,dbpass);cs=conn.prepareCall("{call morf_pro1(?,?)}");cs.setString(1, "SCOTT");cs.setInt(2,999);cs.execute();cs.close();stmt=conn.createStatement();rs=stmt.executeQuery("select morf_fun1('SCOTT') from dual");if(rs.next())System.out.println(rs.getInt(1));rs.close();stmt.close();conn.close();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}