在存储过程中调用java对象作为参数
问题描述:
我想知道我们是否可以将存储过程调用中的java对象作为参数传递。这里是我的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();
}
答
解决这听起来像你问,如果你能做到这一点:
cst = dbConnection.prepareCall("{ call add_patient(?,?,?,?,?,?,?,?,?,?) }");
cst.setObject(1, patientInfo);
在获取准备好的声明的意义,知道分配给什么性质什么数据库字段,那么答案是否定的。
虽然PreparedStatement类实际上有一个setObject()。但它专注于产生特定产出的特定范围的可接受类别。 Java bean不在该列表中。
+0
不。我想知道我们是否可以像传唤add_patient(patientInfo)那样传递patientInfo,在那里我可以从数据库中获得所有的争论。这是一种正确的技术。还是有任何方法可以做这样的事情 – yopirates 2010-11-09 06:21:41
有没有任何方法可以将addInpatient存储过程调用中的patientInfo作为参数传递? – yopirates 2010-11-09 05:40:54