I wanted to know whether we can pass a java object inside the stored procedure call as an argument. Here is my java code where i have used the stored procedure call. Please help me in finding the solution for this
public void addPatientInfo(PatientInfo patientInfo) throws SQLException
{
CallableStatement cst = null;
try {
logger.info("Enter addPatientInfo");
dbConnection = DbConnectionImpl.getDbConnection(d开发者_如何转开发bConnInfo);
dbConnection.setAutoCommit(false);
cst = dbConnection.prepareCall("{ call add_patient(?,?,?,?,?,?,?,?,?,?) }");
cst.setInt(1, patientInfo.getSalutationType().getSalutationTypeId());
cst.setString(2, patientInfo.getFirstName());
cst.setString(3, patientInfo.getMiddleName());
cst.setString(4, patientInfo.getLastName());
cst.setString(5, patientInfo.getGender());
cst.setString(6, patientInfo.getDob());
cst.setString(7, patientInfo.getOccupation());
cst.setInt(8, ApplicationConstants.OWNER_TYPE_PATIENT);
cst.setString(9, patientInfo.getEducation());
cst.setString(10,patientInfo.getPatientIdentityNo());
cst.execute();
dbConnection.commit();
}
It sounds like you are asking if you can do this:
cst = dbConnection.prepareCall("{ call add_patient(?,?,?,?,?,?,?,?,?,?) }");
cst.setObject(1, patientInfo);
In the sense of getting the prepared statement to know what properties to assign to what database fields, then the answer is no.
There is actually a setObject() on the PreparedStatement class though. But it is focused on a specific range of acceptable classes which produce specific output. Java beans are not in that list.
I see what you are saying...
There's a way, but for that you'll have to create an object in Oracle, and map it to Java Object.
精彩评论