Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

java.sql.SQLException: java.lang.ArrayIndexOutOfBoundsException

  Asked By: Arnold    Date: Nov 20    Category: Java    Views: 2980
  

I am getting the following exception when i am calling a stored
procedure from java, i have verified all the in and out parameters
there is no problem in passing parameters. so pls tell me where i am
going wroung.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Shirley Allen     Answered On: Nov 20

It would be to sent some of your code which cause this Exception,but at first glance it seems that there is some thing wrong with your out parameters  that their length doesn't match with the length of variables that you declared in java  or vice versa. Check your CallableStatement set & get methods to find the exact problem.

 
Answer #2    Answered By: Myrna Brown     Answered On: Nov 20

i am pasting my code pls  look into that mena
while i will go a head with ur suggetion.


code---

MiniBundleDTO mbundleDTO = new MiniBundleDTO();
String strArr[] = new String[2];
String SP_ADD_BUNDLE =
"{call "+PMConstants.SP_ADD_BUNDLE+
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}";
logger.info("PMConstants.SP_ADD_BUNDLE:-"+ SP_ADD_BUNDLE);
try {

connection = getDataSource().getConnection();
logger.info("PMConstants.SP_ADD_BUNDLE:-
"+PMConstants.SP_ADD_BUNDLE);
//cstmt = connection.prepareCall(PMConstants.SP_ADD_BUNDLE);
cstmt = connection.prepareCall(SP_ADD_BUNDLE);
cstmt.registerOutParameter(1, OracleTypes.NUMERIC);
/* Bind parameters  sequentially to the callable statement to
be
*passed to the oracle StoredProcedure
*/
strArr = listToString(bundleDTO.getOfferingItems());
logger.debug("strArr:-"+strArr[0]);
cstmt.setString(2, strArr[0]); //passing offering ids
cstmt.setString(3, strArr[1]); //passing offering prices
logger.debug("strArr1:-"+strArr[1]);


/*
cstmt.registerOutParameter(10, OracleTypes.NUMERIC);
cstmt.registerOutParameter(11, OracleTypes.NUMERIC);
cstmt.registerOutParameter(12, OracleTypes.NUMERIC);
cstmt.registerOutParameter(13, OracleTypes.NUMERIC);
*/

cstmt.setString(4, bundleDTO.getBundleName());
logger.debug("getBundleName "+bundleDTO.getBundleName());
cstmt.setString(5, bundleDTO.getBundleDesc());
logger.debug("getBundleDesc "+bundleDTO.getBundleDesc());
cstmt.setString(6, bundleDTO.getLoginId()); //passing created
by
logger.debug("getLoginId "+bundleDTO.getLoginId());
short isBundle = 0;
if(bundleDTO.getProductCategoryDTO().getIsBundle()) {
isBundle = 1;
} else {
isBundle = 0;
}
logger.debug("isBundle "+ isBundle);
cstmt.setShort(7, isBundle);
cstmt.setLong(8, bundleDTO.getSourceDTO().getSourceId());
logger.debug("getSourceId "+ bundleDTO.getSourceDTO
().getSourceId());
long viewTypeId = bundleDTO.getViewtypeDTO().getViewTypeId();
cstmt.setLong(9, viewTypeId);
logger.debug("getViewTypeId "+ bundleDTO.getViewtypeDTO
().getViewTypeId());

//cstmt.registerOutParameter(1,OracleTypes.NUMBER); /casing error


cstmt.registerOutParameter(1, java.sql.Types.NUMERIC); //causing error
//cstmt.registerOutParameter(11, OracleTypes.NUMBER);
//cstmt.registerOutParameter(12, OracleTypes.NUMBER);
//cstmt.registerOutParameter(13, OracleTypes.NUMBER);

logger.info("kaladhar");
cstmt.execute();//going to sql  exception
logger.info("kaladhar1");


long intRetId = cstmt.getLong(1); // Get the Return Error
Code -1
logger.info("OracleBundleDAO:insertBundle()--intRetId" +
intRetId);
if (intRetId == -1) {
logger.error("OracleBundleDAO :- Dupicate Entry :" +
"Bundle Name = " +
bundleDTO.getBundleName());
throw new PMDataException
(PMConstants.MSG_DUPLICATE_BUNDLE);
} else if (intRetId == -2) {
logger.error("OracleBundleDAO :- Offering Id Exists :" +
" BundleName = " +
bundleDTO.getBundleName());
throw new PMDataException
(PMConstants.MSG_OFFERING_ID_NOT_EXIST);
} else {
miniBundleDTO.getProductCategoryDTO().
setProductCategoryId(cstmt.getLong(10));
miniBundleDTO.setwasNewPCReqd((cstmt.getShort(11)==1)?
true:false);
logger.info("OracleBundleDAO:insertBundle()--
setwasNewPCReqd" +
miniBundleDTO.getwasNewPCReqd());
miniBundleDTO.setBundleId(cstmt.getLong(12));
miniBundleDTO.getProductCategoryDTO().getServiceTypeDTO
().
setServiceTypeId(cstmt.getLong(13));
return miniBundleDTO;
}

} catch (SQLException sqe) {
logger.error("SQLException in OracleBundleDAO: " + sqe +
"SP name: " + PMConstants.SP_ADD_BUNDLE + "Bundle Name: "
+
bundleDTO.getBundleName());
throw new PMDataException(sqe);
} catch (Exception e) {
throw new PMDataException("Generic exception  in insertBundle"
+
"method of OracleBundleDAO" + e);
} finally {
// Cleaning up all the jdbc System resources
// Calling the Close Method of the DAOObject
logger.info(new ExitStringBuilder
("OracleBundleDAO:insertBundle()"));
close(cstmt, null, connection);


oracle SP- fields--

SQL_CODE OUT NUMBER,
OFFERINGIDS IN VARCHAR2,
BUNDLEOFFPRICES IN VARCHAR2,
BUNDLENAME IN BUNDLE.BUNDLE%TYPE,
BUNDLEDESCRIPTION IN BUNDLE.BUNDLE_DESCRIPTION%TYPE,
LOGINNAME IN
PARTY_SECURITY.SECURITYSTRING%TYPE,
ISBUNDLE IN NUMBER,
SOURCEID IN SOURCE.SOURCE_ID%TYPE,
VIEWTYPEID IN VIEW_TYPE.VIEW_TYPE_ID%
TYPE,
PRODUCTCATEGORYID OUT
PRODUCT_CATEGORY.PRODUCT_CATEGORY_ID%TYPE,
CATEGORYWASADDED OUT NUMBER,
BUNDLEID OUT BUNDLE.BUNDLE_ID%TYPE,
SERVICETYPEID OUT
SERVICE_TYPE.SERVICE_TYPE_ID%TYPE

 
Answer #3    Answered By: Reginald Thomas     Answered On: Nov 20

Why you are binding out parameter (1) twice.
cstmt.registerOutParameter(1, OracleTypes.NUMERIC);
1.one after prepare call.
2.one after parameter(9)
Check that once.might be this the reason.
you missing parameter 10. check once.