Modifier and Type | Method and Description |
---|---|
static Map<String,Object> |
callStoredProcedure(Connection connection,
String name,
StoredProcedureParameter... parameters)
Calls a stored procedure using a
Connection . |
static Map<String,Object> |
callStoredProcedure(DataSource dataSource,
String name,
StoredProcedureParameter... parameters)
Calls a stored procedure using a
DataSource . |
public static Map<String,Object> callStoredProcedure(DataSource dataSource, String name, StoredProcedureParameter... parameters) throws SQLException
DataSource
.
CREATE PROCEDURE add(x in integer, y in integer, z out integer) IS
BEGIN
z:=x+y;
END;
Then you would use code similar to this to call the stored procedure.
final Map<String, Object> map = callStoredProcedure(dataSource, "add",
new StoredProcedureParameter("x", CType.INTEGER, 70),
new StoredProcedureParameter("y", CType.INTEGER, 10),
new StoredProcedureParameter("z", OUT, CType.INTEGER));
Integer result = (Integer)map.get("z");
}
dataSource
- DataSource used to get a connection from.name
- Name of the stored procedure.parameters
- The (optional) parameters.StoredProcedureParameterType.INOUT
or
StoredProcedureParameterType.OUT
parameter.IllegalArgumentException
- When the supplied name is empty.NullPointerException
- When either the supplied dataSource or the supplied name is null.SQLException
- When the statement could not be executed.public static Map<String,Object> callStoredProcedure(Connection connection, String name, StoredProcedureParameter... parameters) throws SQLException
Connection
.
CREATE PROCEDURE add(x in integer, y in integer, z out integer) IS
BEGIN
z:=x+y;
END;
Then you would use code similar to this to call the stored procedure.
final Map<String, Object> map = callStoredProcedure(dataSource, "add",
new StoredProcedureParameter("x", CType.INTEGER, 70),
new StoredProcedureParameter("y", CType.INTEGER, 10),
new StoredProcedureParameter("z", OUT, CType.INTEGER));
Integer result = (Integer)map.get("z");
}
connection
- The database connection.name
- Name of the stored procedure.parameters
- The (optional) parameters.StoredProcedureParameterType.INOUT
or
StoredProcedureParameterType.OUT
parameter.IllegalArgumentException
- When the supplied name is empty.NullPointerException
- When either the supplied connection or name is null or when one of the supplied parameters
is null.SQLException
- When the statement could not be executed.Copyright © 2008–2018. All rights reserved.