package com.phome.dao;
import java.sql.CallableStatement; import java.sql.Connection; import java.sql.SQLException; import java.sql.Types;
import com.phome.db.DBHerper; //Java调用oracle函数 public class FunctionTest extends DBHerper{ public int testFunction(int num1,int num2){ int tem = 0; Connection conn = null; CallableStatement csmt = null; try { conn = super.getConnection(); csmt = conn.prepareCall("{?=call add_two_num(?,?)}"); csmt.registerOutParameter(1, Types.INTEGER); csmt.setInt(2, num1); csmt.setInt(3, num2); csmt.execute(); tem = csmt.getInt(1); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { csmt.close(); conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return tem; } public static void main(String[] args) { FunctionTest ft = new FunctionTest(); int tem = ft.testFunction(10,20); System.out.println(tem); } }
|