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;   
    }   
}


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。