Call stored function / stored procedure from JAVA/JPA and pass array
I fail calling a plsql function from java with jpa - it works perfect without the array but its not working with the array:
PLSQL Function:
function getHtml(pWhere VARCHAR2 DEFAULT NULL,
pColSort HTP.STRINGARRAY) return clob is
begin
errorhndl.Log(pMessage => 'called');
htp.prn('das ist der test
for i in 1 .. pColSort.count loop
htp.p('
pColSort['||i||']: '||pColSort(i));
end loop;
htp.prn('
<table> <tr> <td> max1.0 </td> <td> max2.0 </td> </tr>');
htp.prn('<tr> <td> max1.1 </td> <td> max2.1 </td> </tr> </table>');
htp.prn('test ende');
return htp.gHtpPClob;
exception
when others then
null;
end getHtml;
PLSQL TYPE: (in HTP package - self created - but could be anywhere else too)
type STRINGARRAY is table of varchar2(256) index by binary_integer;
JAVA DOA:
public class ShowReportDOAImpl implements ShowReportDOA {
private JdbcTemplate jdbcTemplate;
private SimpleJdbcCall procShowReport;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
procShowReport = new SimpleJdbcCall(this.jdbcTemplate)
.withCatalogName("Show_Report")
.withFunctionName("getHtml")
.withoutProcedureColumnMetaDataAccess()
.declareParameters(
new SqlParameter("pWhere", Types.VARCHAR),
new SqlParameter("pColSort", Types.ARRAY, "HTP.STRINGARRAY"),
new SqlOutParameter("RETURN", Types.CLOB)
public String readReport(Long id, ParameterHelper ph) {
String[] sortCol = {"max", "michi", "stefan"};
String pWhere = "fritz";
MapSqlParameterSource parms = new MapSqlParameterSource();
parms.addValue("pWhere", pWhere);
parms.addValue("pColSort", sortCol, Types.ARRAY, "HTP.STRINGARRAY");
parms.addValue("pColSort", Arrays.asList(sortCol), Types.ARRAY, "HTP.STRINGARRAY");
Clob clob = procShowReport.executeFunction(Clob.class, parms);
String clobString = "";
try {
System.out.println("length: "+new Long(clob.length()).intValue());
clobString = clob.getSubString(1, new Long(clob.length()).intValue());
} catch (SQLException e) {
e.printStackTrace();
return clobString;
EXCEPTION IS:
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call SHOW_REPORT.GETHTML(?, ?)}]; SQL state [null]; error code [17059]; Konvertierung zu interner Darstellung nicht erfolgreich: [max, michi, stefan]; nested exception is java.sql.SQLException: Konvertierung zu interner Darstellung nicht erfolgreich: [max, michi, stefan]
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:969)
org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:391)
org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:354)
org.springframework.jdbc.core.simple.SimpleJdbcCall.executeFunction(SimpleJdbcCall.java:154)
at.ontec.cat.config.doa.ShowReportDOAImpl.readReport(ShowReportDOAImpl.java:47)
at.ontec.cat.http.ShowReport.doGet(ShowReport.java:80)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause
java.sql.SQLException: Konvertierung zu interner Darstellung nicht erfolgreich: [max, michi, stefan]
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:161)
oracle.jdbc.driver.DatabaseError.check_error(DatabaseError.java:860)
oracle.sql.ARRAY.toARRAY(ARRAY.java:209)
oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7767)
oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7448)
oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7836)
oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4586)
org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:166)
org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:166)
org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:356)
org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:216)
org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:127)
org.springframework.jdbc.core.CallableStatementCreatorFactory$CallableStatementCreatorImpl.createCallableStatement(CallableStatementCreatorFactory.java:212)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:947)
org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:391)
org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:354)
org.springframework.jdbc.core.simple.SimpleJdbcCall.executeFunction(SimpleJdbcCall.java:154)
at.ontec.cat.config.doa.ShowReportDOAImpl.readReport(ShowReportDOAImpl.java:47)
at.ontec.cat.http.ShowReport.doGet(ShowReport.java:80)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
Please help!!
Please help!!
user8374822 wrote:
PLSQL Function:
function getHtml(pWhere VARCHAR2 DEFAULT NULL,
pColSort HTP.STRINGARRAY) return clob is
begin
end getHtml;
PLSQL TYPE: (in HTP package - self created - but could be anywhere else too)
type STRINGARRAY is table of varchar2(256) index by binary_integer;
JAVA DOA:
new SqlParameter("pColSort", Types.ARRAY, "HTP.STRINGARRAY"),I don't know much (??) java and can't understand your error messages as they are not in english.
But I have a feeling that the error is because either
a) "Types.ARRAY" in Java world probably does not map to an index-by table in oracle or
b) the array must be created as a SQL TYPE and not as a package variable or
c) both of the above
You may want to try following approaches
1) Change the array type declaration to nested table i.e. use "type STRINGARRAY is table of varchar2(256)"
2) If the above does not work, then create a sql type (using CREATE TYPE statement) to create STRINGARRAY as a SQL type of varchar2(256)
Hope this helps.
Similar Messages
-
Call native function fflush & strprn from java
Hi,
I need to call a native function fflush and stdprn from java for printing a file.
How can i call this function?
Can any one help me with sample code.
Thanks,
rpalaniveluThanks your reply,
Actually my problem is need to take printout using dot matrix printer(text printer) with different font size.
So, i am using native method which is available in c.
in c program i am using fflush,stdprn and fprintf.
Here i've attached my sample program also.
#include <jni.h>
#include "NativePrint.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXLINE_LEN 100
JNIEXPORT jint JNICALL
Java_NativePrint_dotMatrixPrint(JNIEnv* env, jobject obj )
FILE *fp;
char filename[20];
char line[100]; /* A line read from the file */
int lineNumber = 0;
/* Print control codes */
char boldOn = 14;
char boldOff = 20;
char contentlenOn = 15;
char contentlenOff = 18;
printf("Printing from C3");
strcpy( filename , "sayHello.c" );
/* Open the file in read mode */
fp = fopen( filename , "r" );
/* Error in opening file, then exit */
if ( fp == NULL )
printf( "\nERROR: %s cannot be opened\n" , filename );
exit( 1 );
while ( fgets( line , 100 , fp ) != NULL )
lineNumber++; /* Line we are about to process next */
printf("%s",line);
/* If this is the first line */
if ( lineNumber == 1 )
/* then print it in bold */
//fprintf( stdprn , "%c" , boldOn );
fprintf( stdprn , "%c" , contentlenOn );
fprintf( stdprn , line );
fprintf( stdprn , "%c" , contentlenOff);
//fprintf( stdprn , "%c" , boldOff );
else
/* else print it in normal mode */
fprintf( stdprn , line );
fflush(stdprn);
return 0; -
How to call a BW WEB template from R/3 and pass parameters to the report
Is it possible to call a BW web template from an R/3 system, through an abap program?
I have a BW WEB report template. This works very good, and i have 3 variables in the query.
Now, i need to invoke the BW web template from inside of an abap in R/3..
And i want to pass 3 variables from the R/3 ABAP to the BW WEB TEMPLATE.....
Is possible to call BW web templates from R/3??
PLEASE!!! HELP ME..
Carlos E. España
ADATSA
[email protected]Thank you very much for your valuable help, i checked your suggestion and looks great. But i need to pass 3 parameters from an ABAP to the wad query report.
How can i pass the parameters to the web template???
another issue: My WAS (Web Application Server 6.20) is not public, is currently working for a local area network.
The access to this report is from outside of the office, so we need to access this through the PORTAL. -
Unable to call a pl/sql procedure from java
Software : Oracle 9i & Red hat linux 9
Code:
import java.io.*;
import java.sql.*;
public class test
public static void main(String args[])
try
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.221:1521:elearn","gowri","gowri");
CallableStatement call=con.prepareCall("{call ins(?,?,?,?)}");
call.setInt(1,5);
call.setString(2,"hari");
call.setString(3,"m");
call.setString(4,"1976-12-26");
if ( call.execute() )
System.out.println("Success");
else
System.out.println("fails");
call.close();
con.close();
catch(Exception ex)
System.out.println("Error :"+ex);
~
~
~
Stored Procedure:
create or replace procedure ins(no in number,name in varchar,sex in varchar,dob in varchar)is
con_day date;
begin
con_day=to_date(dob,'yyyy-mm-dd');
insert into person values(no,name,sex,con_day);
end;
Run Time Error:
Exception in thread "main" java.lang.IncompatibleClassChangeError: oracle.jdbc.driver.OraclePreparedStatement
at 0x40268e17: java.lang.Throwable.Throwable(java.lang.String) (/usr/lib/./libgcj.so.3)
at 0x4025bc8e: java.lang.Error.Error(java.lang.String) (/usr/lib/./libgcj.so.3)
at 0x4025d6b6: java.lang.LinkageError.LinkageError(java.lang.String) (/usr/lib/./libgcj.so.3)
at 0x4025c7aa: java.lang.IncompatibleClassChangeError.IncompatibleClassChangeError(java.lang.String) (/usr/lib/./libgcj.so.3)
at 0x40229eed: JvPrepareClass(java.lang.Class) (/usr/lib/./libgcj.so.3)
at 0x40248028: java.lang.ClassLoader.linkClass0(java.lang.Class) (/usr/lib/./libgcj.so.3)
at 0x4025acb3: java.lang.ClassLoader.resolveClass0(java.lang.Class) (/usr/lib/./libgcj.so.3)
at 0x402299cb: JvPrepareClass(java.lang.Class) (/usr/lib/./libgcj.so.3)
at 0x40248028: java.lang.ClassLoader.linkClass0(java.lang.Class) (/usr/lib/./libgcj.so.3)
at 0x4025acb3: java.lang.ClassLoader.resolveClass0(java.lang.Class) (/usr/lib/./libgcj.so.3)
at 0x4024646c: java.lang.Class.initializeClass() (/usr/lib/./libgcj.so.3)
at 0x40230912: JvInterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
at 0x40230ff4: JvInterpMethod.run(ffi_cif, void, ffi_raw, JvInterpMethodInvocation) (/usr/lib/./libgcj.so.3)
at 0x4022e504: JvInterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/./libgcj.so.3)
at 0x4038305c: ?? (??:0)
at 0x403831e7: ffi_call_SYSV (/usr/lib/./libgcj.so.3)
at 0x403831a7: ffi_raw_call (/usr/lib/./libgcj.so.3)
at 0x402306e8: JvInterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
at 0x40230ff4: JvInterpMethod.run(ffi_cif, void, ffi_raw, JvInterpMethodInvocation) (/usr/lib/./libgcj.so.3)
at 0x4022e58a: JvInterpMethod.run_synch_object(ffi_cif, void, ffi_raw, void) (/usr/lib/./libgcj.so.3)
at 0x4038305c: ?? (??:0)
at 0x403831e7: ffi_call_SYSV (/usr/lib/./libgcj.so.3)
at 0x403831a7: ffi_raw_call (/usr/lib/./libgcj.so.3)
at 0x402306e8: JvInterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
at 0x40230ff4: JvInterpMethod.run(ffi_cif, void, ffi_raw, JvInterpMethodInvocation) (/usr/lib/./libgcj.so.3)
at 0x4022e504: JvInterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/./libgcj.so.3)
at 0x4038305c: ?? (??:0)
at 0x40242dd8: gnu.gcj.runtime.FirstThread.call_main() (/usr/lib/./libgcj.so.3)
at 0x402ad02d: gnu.gcj.runtime.FirstThread.run() (/usr/lib/./libgcj.so.3)
at 0x4024fc4c: JvThreadRun(java.lang.Thread) (/usr/lib/./libgcj.so.3)
at 0x4021c8ac: JvRunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/./libgcj.so.3)
at 0x08048910: ?? (??:0)
at 0x42015574: __libc_start_main (/lib/tls/libc.so.6)
at 0x080486c1: ?? (??:0)Hi Gowrishankar,
This is just a suggestion (based on a guess). Try changing this line of your code:
call.setInt(1,5);with this line:
call.setBigDecimal(1,5);Good Luck,
Avi. -
Call a function in servlet from java class.
Hi,
I am implementing a client/server technology by trying to convert a java desktop client into Browser based. As part of user authetication the only way I know that a username /password does not match is from the servers message as i dont have documentation of the backend servers database.
Here is a fucntion which receives lines form server.
public class ServerComm{
public synchronized void receiveMessage(String serverMessage){
if (serverMessage.equals("Login-Fail"))// Login-Fail is message from server if login fails
LoginHandler.loginFail()//Login Handler is a servlet
return
}The Login Handler servlet is as follows.
public class LoginHandler extends HttpServlet {
/** Initializes the servlet.
public void init(ServletConfig config) throws ServletException {
super.init(config);
/** Destroys the servlet.
public void destroy() {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
protected synchronized void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//some expressions.
//this is reached if login fails.
public static void loginFail(){
HttpServletResponse response;
//redirected to wronglogin web page.
response.sendRedirect("/mCVW/wronglogin.jsp");
/** Handles the HTTP <code>GET</code> method.
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
/** Handles the HTTP <code>POST</code> method.
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}Now there is problem in loginFail() method in LoginHandler servlet does not work with the type of response decleration . I need some assistance from any one to make this work or propose a better solution for determining the user authetication with the restriction i have.
Thank you.hmm...I haven't tried this before...but does this work by any chance?
In your ServerComm class, create new HttpServletRequest and Response objects and get a RequestDispatcher object from request.
Eg : if (serverMessage.equals("login-fail"){
HttpServletRequest request = new HttpServletRequest ();
HttpServletResponse response = new HttpServletResponse ();
request.setAttribute("function_id", "loginFail");
RequestDispatcher dispatcher = request.getRequestDispatcher("http://servername:port/ServletName");
//give the complete path of your servlet
dispatcher.forward(request, response);
and in your Servlet, get this function_id and if its loginFail, redirect it to wronlogin.jsp...
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
String function_id = request.getAttribute("function_id");
if(function_id.equalsIgnoreCase("loginFail"))
//forward to ur jsp
getServletConfig().getServletContext().getRequestDispatcher(wronlogin.jsp").forward(request, response);
} -
Calling stored procedure from Java raises ORA-1722 exception
Hi,
As the title says, when I call the stored procedure from java I got the exception ORA-1722 (invalid number) but I've checked and rechecked my procedure on SQL-Developer and It's alright it works nice and clean !
What's happening? is there something I'm missing?
The way I call the stored procedure is:
public void execProcedure(String procedure) {
CallableStatement cs;
try {
cs = conn.prepareCall(procedure);
cs.execute();
} catch (SQLException ex) {
Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
where
String procedure = "{call validateinfo}"I really need help on this, it's frustraiting me 'cause I need to finish a system but this little big problem is killing me ...
Thanks any advice is very welcome :)Thanks for your help. Haven't tested the SP with a DB access client... which one do you recommend to use?
The SP is the following:
create or replace
PROCEDURE validateInfo IS
var number;
BEGIN
UPDATE temp_desarrollo
SET status = '1';
COMMIT;
// Some string validations ...
//This one just checks if the value of "monto" is a number
//This update goes good
UPDATE temp_desarrollo tmp
SET cve_status = Decode(cve_status, NULL, '15', cve_status||',15')
WHERE IsNumber(tmp.monto) = 'F';
COMMIT;*/
//This one just checks if the value of "monto" is greater than 0
//if not, change de add to cve_status an errorValue
UPDATE temp_desarrollo tmp
SET cve_status = Decode(cve_status, NULL, '14', cve_status||',14')
WHERE (cve_status NOT LIKE '%15%' OR cve_status IS NULL)
AND to_number(tmp.monto) <= 0;
COMMIT;
//More string validations
EXCEPTION
WHEN OTHERS THEN
var := SQLCODE;
insert into excepciones values(to_char(var));
END;I've deleted much code from the SP since I know there's nothing to do with the excepcion, just that UPDATE statement is the one giving me the exception.
If those two UPDATES statements work with the same field (monto) why the first one is succeding and the second one not?
Cheers,
Federico
P.S. the "isNumber" function is as follows, just in case.
create or replace
function IsNumber(val1 varchar2) return varchar2 is
n number := null;
begin
n := to_number(val1,'9999999999999999.99');
return 'T';
exception
when others then
return 'F';
end; -
Calling Stored Procedures from JAVA Application
Hi all,
i am using JDeveloper 3.2.2 for creating a DB Application that
uses Oracle8i as DB Server.
One approach of the application is to only use PL/SQL Stored
Procedures to write Data back to the DB.
Some of the stored procedures expect more than 20 parameters.
I want to know if there is a better way to call such a stored
procedure from Java than using a CallableStatement and setting
its 20 parameters.
Another reason why the way above isnt possible for me is that
i need a dynamic way to set the parameters of the stored
procedure.
A solution for that dynamic way i could think of is to get
the information of the stored procedure by using some functions
of DatabaseMetaData and than use this information to map the
parameters with their respective variables in the java
application.
The best argument against this way is that it would be time and
performance consuming.
So could anybody tell me a solution to call PL/SQL stored
procedures from java which is better than doing something like:
String calString = "{Call myStoredProc(";
while(counter < 22) {
params += "?";
if(counter<21) params += ",";
counter++;
calString += params + ")}";
try {
CallableStatement cs = session.prepareCall(calString);
} catch(SQLException ex) { ... }
cs.setString(1, var1);
cs.setString(1, var2);
And that for every Stored Procedure i want to call ?!?
Any help or direction-leading would be really appreciated.
Tank you much.
MfG,
Oliver BankelHi Oliver,
If you your Stored Procedures were in Java and seamlessly
integrated with your Java application would that make your life
easier?
I don't know if this is a practical or acceptable solution in
your environment but it would certainly solve all of your issues
and provide your with a couple of nice advantages. Scalability
and platform independence are just a couple I could think of.
There is a tool called in2j (see http://www.in2j.com) which will
automatically migrate your PL/SQL Stored Procedures into Java.
You can download a copy of the tool and migrate your PL/SQL to
Java with no upfront costs. If you're happy with the generated
Java and want to deploy it, the migration fee falls due - simple.
Hope this helps.
Elton -
Calling packaged stored procedure from Java
Hi All,
I'm trying to call a stored procedure from Java but I'm having
problems with registrating the output parameter. I'm getting
the error: Conflicting parameters.: sqltype=2003
This is the stored procedure which is located in a package in
the Oracle database:
package Pack_GetAgencyInformation as
Type InfoType is record ( agen_code varchar(3), agen_designation
varchar(30), agen_adresse varchar(60), agen_tel varchar(12) );
function GetAgencyInformation( P_AGENCE VARCHAR )
return Pack_GetAgencyInformation.InfoType
end Pack_GetAgencyInformation;
This is the Java source from where I'm calling the procedure:
//DriverManager.registerDriver (new
oracle.jdbc.driver.OracleDriver());
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@164.48.69.125:1521:ventes", "system", "*****
// @machineName:port:SID,
userid, password
CallableStatement cs = conn.prepareCall("{ ? = call
Pack_GetAgencyInformation.GetAgencyInformation( ? )}");
try {
cs.registerOutParameter( 1,
oracle.jdbc.driver.OracleTypes.ARRAY);
} catch (SQLException e) {
e.printStackTrace();
cs.setString(2, "001" );
//ResultSet rset = cs.executeQuery();
The stacktrace:
java.sql.SQLException: Parametertypen conflicteren.:
sqlType=2003
at oracle.jdbc.dbaccess.DBError.throwSqlException
(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException
(DBError.java:210)
at
oracle.jdbc.driver.OracleCallableStatement.registerOutParameter
(OracleCallableStatement.java:220)
at
oracle.jdbc.driver.OracleCallableStatement.registerOutParameter
(OracleCallableStatement.java:350)
at dbAccess.main(dbAccess.java:25)
I think it has to do with the type InfoType which is created in
the Stored Procedure. I'm absolute no Oracle expert and I
prefer not to make changes to the Oracle database. So any
solution in Java is welcome!
BR, H.RietmanI managed to get it to work only by changing the stored
procedure. I have changed the return type record to a Ref
Cursor type (had to change alot of code for this). It seams
that Oracle JDBC drivers DON'T support the Record type as a
return type.
So the next question is: is it possible to typecast a record
type to a ref cursor type in Oracle. In this way I can easily
change the return type for the stored procedures.
/Harald -
Error while calling stored procedure from Java
Hi Guys,
How are you everybody? I hope everything is goin fine on your side. I have one issue in PL/SQL while calling below stored procedures from Java.
Problem Description: We have a stored procedure PROCEDURE BULK_INSERTS (
V_SESSION_ID_TAB IN T_SESSION_ID_TAB_TYPE,
V_SERVICE_TYPE_TAB IN T_SERVICE_TYPE_TAB_TYPE,
V_SERVICE_LOCATION_TAB IN T_SERVICE_LOCATION_TAB_TYPE,
V_SERVICE_CALL_NAME_TAB IN T_SERVICE_CALL_NAME_TAB_TYPE,
V_SERVICE_CALL_START_TIME_TAB IN T_SERVICE_CALL_ST_TAB_TYPE,
V_SERVICE_CALL_END_TIME_TAB IN T_SERVICE_CALL_ET_TAB_TYPE,
V_SERVICE_CALL_DURATION_TAB IN T_SERVICE_CALL_DUR_TAB_TYPE,
V_STATUS_TAB IN T_STATUS_TAB_TYPE,
V_NOTES_TAB IN T_NOTES_TAB_TYPE
) and we are getting ora errors while calling this stored procedure from java.
All tab types are declared locally, at package level.
Here is error which occur while calling this sp:
{call BULK_PKG.BULK_INSERTS(?,?,?,?,?,?,?,?,?)}
And the parameter types we are using are:
SESSION_ID - NUM_TAB_TYPE
SERVICE_TYPE - VAR_TAB_TYPE
SERVICE_LOCATION - VAR_TAB_TYPE
SERVICE_CALL_NAME - VAR_TAB_TYPE
SERVICE_CALL_START_TIME - DATE_TIME_TAB_TYPE
SERVICE_CALL_END_TIME - DATE_TIME_TAB_TYPE
SERVICE_CALL_DURATION - NUM_TAB_TYPE
STATUS - VAR_TAB_TYPE
NOTES - VAR_TAB_TYPE
And the Exception stack trace is:
ERROR (com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.saveExternalServiceCallInfo(ExternalServi
ceCallDAO.java:143)@ExecuteThread: '252' for queue: 'weblogic.kernel.Default') {Error attempting to save collected ESC data}
java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:191)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:944)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3381)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3482)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:3856)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1373)
at weblogic.jdbc.wrapper.PreparedStatement.execute(PreparedStatement.java:98)
at com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.doBulkInsert(ExternalServiceCallDAO.java:220)
at com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.saveExternalServiceCallInfo(ExternalServiceCallDAO.java:138)
Please help my guys out of this. I will really appreciate all suggestions and advices.
Thank you everybody.I am trying to pass parameter to test my procedure but it is giving this error : ORA-06531: Reference to uninitialized collection
ORA-06512: at line 12
Here is example for my test procedure:
declare
v_session_id_tab SESSION_ID_TAB_TYPE;
v_service_type_tab SERVICE_TYPE_TAB_TYPE ;
v_service_location_tab SERVICE_LOCATION_TAB_TYPE ;
v_service_call_name_tab SERVICE_CALL_NAME_TAB_TYPE;
v_service_call_start_time_tab SERVICE_CALL_ST_TAB_TYPE;
v_service_call_end_time_tab SERVICE_CALL_ET_TAB_TYPE;
v_service_call_duration_tab SERVICE_CALL_DUR_TAB_TYPE;
v_status_tab STATUS_TAB_TYPE;
v_notes_tab NOTES_TAB_TYPE;
begin
v_session_id_tab(1) := 1;
v_service_type_tab(1) := 'db';
v_service_location_tab(1) := 'local';
v_service_call_name_tab(1) := 'Name of call';
v_service_call_start_time_tab(1) := SYSDATE;
v_service_call_end_time_tab(1) := SYSDATE;
v_service_call_duration_tab(1) := 100;
v_status_tab(1) := 'Z';
v_notes_tab(1) := 'NOTES';
BULK_INSERTS (v_session_id_tab,v_service_type_tab, v_service_location_tab,v_service_call_name_tab,v_service_call_start_time_tab,v_service_call_end_time_tab,
v_service_call_duration_tab, v_status_tab, v_notes_tab);
end;
I declare all types at schema level.
Please give your comments.
Thank you -
Problem in calling Oracle stored procedure from Java.
I am trying to invoke the Oracle stored procedure from Java. The procedure does not take any parameters and does not return anything. If I call it from SQL prompt it is working perfectly. I am calling it in my program as follows.
callable_stmt=con.prepareCall("{call pkg_name.proc_name()}");
callable_stmt.execute();
The problem is the control-of-flow is getting strucked in the second line I wrote. It is not giving any error also.
Please clarify me what's wrong with my code?
Seenu.And how long does the stored procedure take to run from your client machine when running it via sqlplus?
-
How to send a Varying Array param to a PL/SQL Stored Procedure from Java
* I am VERY new to jdbc, and even somewhat new to Java
* I'm using Java 1.5, Oracle 10g.
* I need to call the following PL/SQL Stored Procedure from Java:
procedure setEventStatus
i_deQueueStatus in deQueueStatus_type
*deQueueStatus_type is the following (an array of deQueueStatus_OBJ):
CREATE OR REPLACE TYPE deQueueStatus_OBJ as object
eventID number (20),
dequeuestatus varchar2(20)
CREATE OR REPLACE TYPE deQueueStatus_TYPE IS VARYING ARRAY(500) of deQueueStatus_obj
*I have created a Java object as follows:
public class EventQueueDeQueueStatus
long eventID;
String dequeueStatus;
EventQueueDeQueueStatus(long eventID, String dequeueStatus)
this.eventID = eventID;
this.dequeueStatus = dequeueStatus;
I have an ArrayList of these.
I need to pass this list to the Stored Procedure. How do I create a java.sql.Array so I can call CallableStatement.setArray to set the parameter? Or do I use something else? I have tried setObject with both the ArrayList and also with a primitive array, but got "Invalid Column Type" both times.
Any help would be greatly appreciated. I just got this task today, and I have to make it work by Tuesday :-( !
Thanks,
KathyKathy,
Search the archives of this forum and the JDBC forum for the terms STRUCT and ARRAY and you can find some sample code on the JDBC How-To Documents page and the JDBC Samples which can both be accessed from this page:
http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
Good Luck,
Avi. -
DB2 Stored Procedure from Java-JDBC
Hi All,
I am using DB2 stored procedure which have been written in COBOL. I have two types of stored procedures. First types of stored procedure takes IN parameter and returns OUT parameter. These stored procedures are working fine. The second type of stored procedure takes IN parameter and returns a CURSOR. According to Database team (who wrote these stored procedure) claims that they can see data in a cursor when they test these stored procedure directly in the database. However, when I run these stored procedures from Java code it returns NULL ResultSet. Here is the code:
public SearchResult getAllBenefitHEDType(SearchParameter searchParam) throws DAOException {
log.debug(" getAllBenefitHEDType method - entering ");
HashMap searchParametersMap = searchParam.getHashMap();
SearchResult searchResult = new SearchResult();
String type = (String) searchParametersMap.get(UDFConstant.LOOKUP_SEARCH_TYPE);
HashMap resultParametersMap = new HashMap();
ArrayList resultSetDTO = new ArrayList();
try {
conn = this.getConnection();
conn.setAutoCommit(false);
System.out.println("getAllBenefitHEDType Step 1");
CallableStatement cs = conn.prepareCall("{call TEST.APS003(?)}"); // Stored Procedure with one IN parameter.
cs.setString(1,type);
boolean retVal = cs.execute(); // this should return true if ResultSet is available.. in my case it is returning false.
// I tried with getting the Object
ResultSet rs = (ResultSet) cs.getObject(1); // this should give me a valid result set ... in my case I am getting null
if (rs!=null) {
System.out.println("getAllBenefitHEDType Step 4A Result Set Not Null");
} else {
System.out.println("getAllBenefitHEDType Step 4A Result Set Is Null");
// I tried getting the resultset
ResultSet rs1 = cs.getResultSet(); // this should give me a valid result set ... in my case I am getting null
if (rs1!=null) {
System.out.println("getAllBenefitHEDType Step 4D Result Set Not Null");
} else {
System.out.println("getAllBenefitHEDType Step 4D Result Set Is Null");
while (rs.next()) {
System.out.println("getAllBenefitHEDType Step 5");
LookupDTO lookupDTO = new LookupDTO();
// the following code populate the Lookup DTOs from ResultSet.A few comments...
1) Creating tables, particularly tables whose names seem to imply that they are temporary tables, on the fly in a stored procedure is a bad idea. That is not the way to work with Oracle, though it is a common practice in other databases like SQL Server. There is undoubtedly a better way to do this in Oracle if you can explain what you're trying to accomplish from a business standpoint.
2) If you are going to use dynamic SQL, you almost always want to use bind variables, not literals. One of the quickest ways to kill an Oracle database's performance is to not use bind variables.
3) As has already been mentioned, assuming FH_INICIO is a DATE column, you need to put an explicit TO_DATE around your strings in order to convert them to dates. Otherwise, Oracle's implicit cast depends on the session's NLS_DATE_FORMAT, which is likely to be different in different client applications and from different client machines.
Justin -
Calling stored procedure from page process and PLS-00049 error?
Good morning guys!
I'm dealing with several problems this morning! The one that I need to deal with first is the following.
I created the page process (see below: 1st code) in order to validate if all records where LNG_GEBIET matches have the status 3 or 4. If that is the case I want to call the procedure "set_status_arbeit_zu_gebiet". If amountrs and countstat do not match, then nothing is supposed to be done.
The problem lies within the stored procedure itself. I receive a PLS-00049 bind variable error for :new.LNG_GEBIET.
Can you please tell me what I forgot to declare in code 2 below???
Thank you guys!
The page process:
Declare
amountrs number;
countstat number;
begin
SELECT COUNT(*) INTO amountrs FROM TBL_PUNKTDATEN where LNG_GEBIET = :P4_CNT_GEBIET;
SELECT COUNT(*) INTO countstat FROM TBL_PUNKTDATEN where LNG_GEBIET = :P4_CNT_GEBIET and INT_STATUS = 3 or LNG_GEBIET = :P4_CNT_GEBIET and INT_STATUS = 4;
IF amountrs = countstat THEN
set_status_arbeit_zu_gebiet;
ELSE
dbms_output.put('nothing');
END IF ;
end;Code 2 with the true problem!
CREATE OR REPLACE PROCEDURE set_status_arbeit_zu_gebiet
IS
cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET;
v_c2 c2%ROWTYPE;
BEGIN
open c2;
fetch c2 into v_c2;
if c2%notfound then
INSERT INTO TBL_ARBEIT_ZU_GEBIET
LNG_GEBIET,
LNG_ARBEITSSCHRITT,
PNUM,
INT_BEARBEITER,
DATE_DATUM,
GEPL_DATUM
VALUES
(:new.LNG_GEBIET,
52,
1114,
895,
sysdate,
to_date('01.01.1990', 'DD.MM.YYYY')
commit;
close c2;
END set_status_arbeit_zu_gebiet;One more question: Is it possible to integrate the first validation that calls my stored procedure into code 2?
Thanks for you time!
SebastianThe error is in following statement:
INSERT INTO TBL_ARBEIT_ZU_GEBIET ( ... ) VALUES ( :new.LNG_GEBIET, ... );
As the statement is part of a procedure and not trigger so it is not able to bind this variable with any value.
As a resolution, pass this value to the procedure from the process and use it in the insert statement.
The process will have following IF statement:_
IF amountrs = countstat THEN
set_status_arbeit_zu_gebiet *(:P4_CNT_GEBIET)*;
ELSE
dbms_output.put('nothing');
END IF ;
and the procedure will be as follows:_
CREATE OR REPLACE PROCEDURE set_status_arbeit_zu_gebiet *(p_lng_gebit varchar2)*
IS
cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET= --:new.LNG_GEBIET-- p_lng_gebit ;
v_c2 c2%ROWTYPE;
BEGIN
INSERT INTO TBL_ARBEIT_ZU_GEBIET ( ... )
VALUES
( --:new.LNG_GEBIET-- p_lng_gebit, ... );
END set_status_arbeit_zu_gebiet; -
Need coding support for Accessing MYSQL stored procedure from java
Hi every one,
I need coding support for accessing Mysql stored procedure from java and JSP.
Please help me
pranavYou'd better have a recent version of MySQL, because earlier ones didn't support stored procs.
If your MySQL and driver support stored procs, maybe you just need a JDBC stored proc tutorial.
% -
How to run the Oracle Triggers,Functions and Procedures from java
Hi ,
I want to execute the Oracle's Triggers, Functions and Procedures from java as like executing the SQL commands by using Execute statements.
Or can we have some other option for doing this.
Plz help me ...you can use CallableStatement interface of JDBC to execute any DBMS triger,stored procedure ....
refer any of the JDBC book for extra help
hope you got it
Azeem Ahmed
Maybe you are looking for
-
StarOffice 8 PU1 changes the language of my GUI
Hi, I have installed StarOffice 8 on my Win XP laptop and then product update 1. Now my dropdown menu items show up in German. How do I fix this ? Thank you F.
-
Make "Share Link" instantly create link and copy to the clipboard
This one you should lift from Dropbox. When right-clicking a file and selecting Share Link, don't send me out to creative.adobe.com. Just make me a public link and copy it to my clipboard, allowing me to paste it into a message, email, tweet, whateve
-
I just changed over to Comcast and updated added my accounts to the mail program. I added 5 accounts from Comcast. All work fine except for one. The settings are all EXACTLY the same for each account. However, I cannot send to (nor receive from...) t
-
The "i" in all the software & hardware?
I didn't know where to post this so here it is! A friend asked me the other day what the "i" meant in itunes & the others. Does it mean anything & if so what? Thanks, Harris
-
Captivate Crashes When Editing Question Pool
Captivate v5.5 I have a project with 36 questions in a question pool. I need to edit some the these QP questions but as soon as I start doing this I get the message that Captivate has encountered an error...very sorry...and must close down. I have tr