我想知道我们是否可以在存储过程调用中传递一个java对象作为参数。下面是我使用存储过程调用的java代码。请帮我找出解决这个问题的办法
public void addPatientInfo(PatientInfo patientInfo) throws SQLException
{
CallableStatement cst = null;
try {
logger.info("Enter addPatientInfo");
dbConnection = DbConnectionImpl.getDbConnection(dbConnInfo);
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();
}发布于 2010-11-09 14:00:50
听起来你是在问你是否能做到这一点:
cst = dbConnection.prepareCall("{ call add_patient(?,?,?,?,?,?,?,?,?,?) }");
cst.setObject(1, patientInfo);从让预准备语句知道要分配给数据库字段的属性的意义上来说,答案是否定的。
不过,在PreparedStatement类上实际上有一个setObject()。但它专注于产生特定输出的特定范围的可接受类。Java bean不在该列表中。
发布于 2010-11-10 01:22:30
我明白你的意思了。
有一种方法,但是您必须使用create an object in Oracle,并将其映射到Java Object。
https://stackoverflow.com/questions/4130798
复制相似问题