我在eclipse中执行了一个代码,我的目标是在postgres数据库中调用一个存储过程。我尝试从servlet传递的值并得到此错误: "偏移量为1的格式错误的函数或过程转义语法。"
所以现在我尝试对这些值进行硬编码。仍然是同样的问题。什么是抵消?请帮我解决错误。我已经检查了字段的顺序和数据类型。它们是正确的。
public int dispCustomer3(Cust cc){
con=dbCon.getConnection();
//PreparedStatement ps3=null;
System.out.println("inside update function ");
CallableStatement callableStatement =null;
try {
callableStatement=con.prepareCall("{SELECT fn_UpdateCustomer(37, 'Test_Customer56','Test_Customer56','Requirement','Customer_Location',NULL,2,2,NULL,'Customer_Contact_Info','Account_Contact_Info','01-02-2016','01-04-2016',5,'Comments',1,2);}");
/*callableStatement.setInt(1,cc.getCustId());
callableStatement.setString(2,cc.getShortName());
callableStatement.setString(3,cc.getStatus_name() );
callableStatement.setString(4,cc.getRequirement());
callableStatement.setString(5,cc.getCustomer_location());
callableStatement.setInt(6,cc.getDemo_location_type_id());
callableStatement.setInt(7, cc.getDeployment_type_id());
callableStatement.setInt(8, cc.getRequested_by_id());
callableStatement.setInt(9, cc.getPilot_resource_id());
callableStatement.setString(10, cc.getCustomer_contact_info());
callableStatement.setString(11, cc.getAccount_contact_info());
callableStatement.setDate(12, cc.getDemo_planned_on());
callableStatement.setDate(13, cc.getDemo_actual_on());
callableStatement.setInt(14, cc.getStatus_id());
callableStatement.setString(15, cc.getComments());*/
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{dbCon.closeConnection(con);}
return 1;
}
}
答案 0 :(得分:1)
使用CallableStatement
时,您应该CALL
您的程序,而不是SELECT
。类似的东西:
callableStatement=con.prepareCall("{CALL fn_UpdateCustomer(37, 'Test_Customer56','Test_Customer56','Requirement','Customer_Location',NULL,2,2,NULL,'Customer_Contact_Info','Account_Contact_Info','01-02-2016','01-04-2016',5,'Comments',1,2)}");
您收到的错误Malformed function or procedure escape syntax at offset 1
是指SELECT
关键字。