java调用oracle函数

/**
	 * 调用函数取得数据表的ID值 
	 * @param tableName 表名
	 * @return
	 * @throws SQLException
	 */
	public String callFun(String tableName) throws SQLException {
		Connection conn = ConnectionFactory.getConnection();
		CallableStatement cstmt = null;
		cstmt = conn.prepareCall("{?

=call getIdBySeq(?)}"); cstmt.registerOutParameter(1, Types.VARCHAR); cstmt.setString(2, tableName); cstmt.execute(); return cstmt.getString(1); }

public class ConnectionFactory {

	private ConnectionFactory() {
	}

	private static ComboPooledDataSource ds = null;

	public static synchronized Connection getConnection() {   
        Connection con = null;   
        ds = new ComboPooledDataSource();
        try {   
            con = ds.getConnection();   
        } catch (SQLException e1) {   
            e1.printStackTrace();   
        }   
        return con;   
    }   
}


posted @ 2017-04-28 10:49  wzzkaifa  阅读(454)  评论(0编辑  收藏  举报