Oracle procedu calling in java

Hi Experts,
i'm calling store procedure in java i'm executing fine.

But when i chenge the value in store procedure my java will giving exception.

i'm changing value in store procedure like "open pCur for select * from xxx@cc3 where tstamp=pEndDate"
this code executing fine but when i change above code like "vSql long;begin
vSql:='select * from xxx@cc3 where tstamp=pEndDate';
then "open pCur for vSql" i just change.
then java will giving error

java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-01003: no statement parsed

      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:330)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:287)
      at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:742)
      at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:209)
      at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:950)
      at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1159)
      at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3284)
      at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3328)
      at com.att.network.test.Dbtest.main(Dbtest.java:75)

please give me some suggestion.
thanks.

my store procedure
 
create or replace package body testPKG is
 
 
  procedure testtt (
 
  pRepKeys	IN		VARCHAR2,
	pMetKeys	IN		VARCHAR2,
	pPerType	IN		VARCHAR2,
	pEntity		IN		VARCHAR2,
	pBegDate	IN OUT	DATE,
	pEndDate	IN OUT	DATE,
	pGrpBy		IN		VARCHAR2 default null,
	pAggOrd		IN		VARCHAR2 DEFAULT 'T',
	pMonSummary IN		CHAR DEFAULT 'Y',
	pSkipDays	IN		VARCHAR2 DEFAULT NULL,
	pWeekBeg	IN		CHAR DEFAULT 'SUN',
	PSpecificHour	IN	CHAR DEFAULT 'AH',
	pUser_key	IN		VARCHAR2,
	pOSlogin	IN		VARCHAR2,
	pCur		OUT		cv_Type
  )
  is
 
dd  NUMBER;
vSql long;begin
 vSql:='select * from mnn.tf_sectorrtb_summary@cnnw3 where tstamp=pEndDate';
	open pCur for vSql;
 
 
 
  EXCEPTION
    WHEN OTHERS THEN
        ---  tt:= SUBSTR(SQLERRM,1,150);
       dbms_output.put_line('var_err_msg ' || SUBSTR(SQLERRM,1,150));
       --tt:=sysdate;
end testtt;
 
end testPKG;
 
 
my java code:
 
import oracle.jdbc.driver.OracleTypes;
 
import java.sql.*;
import java.text.SimpleDateFormat;
 
 
public class Dbtest {
	
 
	public static Date stringToDate(String strDT){
		java.sql.Date sqltDate= null; 
		String jdbcDate =null;
		
 
		try{
		
			SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
			java.util.Date dd = sdf.parse(strDT);
			jdbcDate = sdf.format(dd);
			sqltDate = new java.sql.Date(dd.getTime());
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("Exception--->"+e.toString());
		}
		  return sqltDate ;
	}
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String s1="12058,12059";
		String s2="16085,16070,16075";
		String s3="DAY";
		String s4="MARKET";
		String s5="17-MAR-2009";
		String s6="17-MAR-2009";
		String s7="N";
		String s8="T";
		String s9="N";
		String s10="";
		String s11="SUN";
		String s12="AH";
		int i=1100;
		String s14="CINGULARUS\\lf1484";
		Connection db_connection=null;
	    
	    
		try{		
			
			Class.forName("oracle.jdbc.OracleDriver");
			String url = "jdbc:oracle:thin:@10.180.190.63:1500:xxx";
			db_connection =DriverManager.getConnection (url, "yyy", "xxx");
		CallableStatement pstmt = db_connection.prepareCall("begin testPKG.testtt(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);end;");
		pstmt.setString(1,"12058");
		pstmt.setString(2,"16085");
		pstmt.setString(3,"DAY");
		pstmt.setString(4,"MARKET");
		pstmt.registerOutParameter(5, java.sql.Types.DATE);
		pstmt.setDate(5,stringToDate(s5));
		pstmt.registerOutParameter(6, java.sql.Types.DATE);
		pstmt.setDate(6,stringToDate(s6));
		pstmt.setString(7,"");
		pstmt.setString(8,"T");
		pstmt.setString(9,"N");
		pstmt.setString(10,"N");
		pstmt.setString(11,"SUN");
		pstmt.setString(12,"AH");
		pstmt.setString(13,"1100");
		pstmt.setString(14,"AUTOLOGIN");
		pstmt.registerOutParameter(15, OracleTypes.CURSOR);
		pstmt.executeQuery();
		ResultSet rs= (ResultSet)pstmt.getObject(15);
		while (rs.next()) {
			System.out.println("object value--->"+rs.getString(1));
			
		}
		ResultSetMetaData rm=rs.getMetaData();
		int columnCount = rm.getColumnCount();
		System.out.println("Number of Column:"+columnCount);
		for(int m=1;m<columnCount;m++){
			System.out.println("Column Name--->"+rm.getColumnName(m));
		}
	
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				db_connection.close();
 
				}catch(Exception e){
			e.printStackTrace();
		}
		}
 
	}
 
}

Open in new window

krish12345Asked:
Who is Participating?
 
johnsoneSenior Oracle DBACommented:
Your problem is that you put the variable name inside the string.  PL/SQL doesn't know what it is.

Change these 2 lines:

 vSql:='select * from mnn.tf_sectorrtb_summary@cnnw3 where tstamp=pEndDate';
        open pCur for vSql;


To:

 vSql:='select * from mnn.tf_sectorrtb_summary@cnnw3 where tstamp= :x';
        open pCur for vSql using pEndDate;
0
 
krish12345Author Commented:
Thanks very much.
0
 
krish12345Author Commented:
Hi Expert,
sorry i change above fuction like this

vSql := FetchNWDataString(pRepKeys,pMetKeys,pPerType,pEntity,pBegDate,pEndDate,pGrpBy,pAggOrd,pMonSummary,pSkipDays,pWeekBeg,PSpecificHour);

could you tell me how I can call.
i'm getting same error.

please help me.
thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.