Taking control back while calling stored procedure using java programme
I have stored procedure to load data. This procedure is invoked by java program.
The stored procedure take around 10 to 15 minutes to do complete loading of database. I want to write stored procedure when it starts loading of database at the same return the control to calling java programme so that java program can do other operation i.e. java program can not wait for control back from stored procedure.
In short stored procedure runs in background and return control back to java program when stored procedure is invoked. Is it possible then How we can achieve this.
U can acheive this using Java Threads. Create a thread submit this loading job. Once you submit the thread, you will get the control back to do other stuff.
Documentation:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html
-aijaz
Similar Messages
-
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 -
ORA-17002 and ORA-17009 while calling Stored Procedures
Hi,
We are developing a JDBC application using WebLogic 6.0 as AppServer. When we
rolled out the application in production, things work fine for about a day or
so, then calls to Stored Procedures start giving ORA-17002 (io exception) and
ORA-17009 (Closed Statement) exceptions while calling Stored Procedures. Restarting
the server 'fixes' the problem for one more day.... We are not able to reproduce
this behaviour in test or development servers.
Can anybody suggest something.....
Regards,
Usman.Usman wrote:
>
Hi,
We are developing a JDBC application using WebLogic 6.0 as AppServer. When we
rolled out the application in production, things work fine for about a day or
so, then calls to Stored Procedures start giving ORA-17002 (io exception) and
ORA-17009 (Closed Statement) exceptions while calling Stored Procedures. Restarting
the server 'fixes' the problem for one more day.... We are not able to reproduce
this behaviour in test or development servers.
Can anybody suggest something.....
Regards,
Usman.Hi. Describe how you are obtaining and using pool connections. Also, do download the
latest thin driver from Oracle, because they have recently fixed some serious
bugs in it.
Let me know,
Joe -
Weird Problem calling Stored Procedure using JDBC
Scenario is..
I have J2EE application and calling stored procedure using JDBC.
My application connects to instance "A" of testDB.
Schema "A" does NOT own any packages/procedure but granted execute on oracle packages/procedures that reside in schema "B" of testDB.
In java code I call procedure(proc1) in package(pac1) which internally calls procedure(proc2) in package(pac2).
The problem occurs when procedure pac2.proc2 is modified. After the modification, my java code fails and throws an exception "User-Defined Exception" and I am also getting "ORA-06508: PL/SQL: could not find program unit being called". This clears up only if I bounce the web container. (This doesn't happen if I modify pac1.proc1 and run my application)
Has any one faced this problem? Please suggest if any thing can be changed in jdbc code to fix this problem.
ThanksHi,
I assume these are PL/SQL packages and that the changes are made at the package specification level?
If so, it looks like you are hitting the PL/SQL dependencies rules. In other words, if the spec of proc2 is changed, then proc1 is invalidated, since proc1 still depends on the old version of proc2's spec. As a result, if you try to run proc1, its spec must either be explicitly rewritten before it could run again or implicitly recompiled first, if the (implicit) recompilation fails, it won’t run.
Kuassi http://db360.blogspot.com -
Conversion of java Array to oracle SQL Array while calling Stored Procedure
How java Array can be converted to oracle SQL array while calling Stored procedure with callable statement.
i.e java Array ---> Sql Array in Oracle while setting the datatypes to callable statement arguments.Look at:
http://forum.java.sun.com/thread.jsp?forum=48&thread=376735&tstart=0&trange=15
Paul -
Creating and calling stored procedure using jdbc
When I try to create and call a stored procedure using JDBC a very confusing error message about non-existence of the procedure just created is thrown. Using Informix database (IDS 10). Any pointers to point out what am doing wrong would be great!
Thanks
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
public class CreateStoredProc {
public static void main(String args[]){
if (0 == args.length)
return;
try {
Class.forName("com.informix.jdbc.IfxDriver");
Connection conn = DriverManager.getConnection("jdbc:informix-sqli://10.76.244.120:30000/sampledb:INFORMIXSERVER=krisunda;user=root;password=cisco");
String q = " create procedure runproc() "+
" define i int; "+
" let i = 0; "+
" end procedure; "+
" execute procedure runproc(); ";
Statement stmt = conn.createStatement ();
stmt.execute (q);
} catch (Exception e) {
e.printStackTrace();
The stack trace:
java.sql.SQLException: Routine (runproc) can not be resolved.
at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3204)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3518)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2353)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2269)
at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2157)
at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2132)
at com.informix.jdbc.IfxResultSet.b(IfxResultSet.java:378)
at com.informix.jdbc.IfxStatement.a(IfxStatement.java:1299)
at com.informix.jdbc.IfxStatement.executeImpl(IfxStatement.java:1269)
at com.informix.jdbc.IfxStatement.c(IfxStatement.java:989)
at com.informix.jdbc.IfxStatement.execute(IfxStatement.java:875)
at CreateStoredProc.main(CreateStoredProc.java:37)
Caused by: java.sql.SQLException
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:373)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3523)
... 10 moreDriverManager.getConnection("jdbc:informix-sqli://10.76.244.120:30000/sampledb:INFORMIXSERVER=krisunda;user=root;password=cisco");check with ur sys admin wheather the particular user in the database has >execute privilage(rights) also.i mean execute the SP in the DB level.I guess that a root user will have the enough right.
String q = " create procedure runproc() "+
" define i int; "+<" let i = 0; "+
" end procedure; "+
" execute procedure runproc(); ";
Statement stmt = conn.createStatement ();
stmt.execute (q);Try to use the following code:
String q = " create procedure runproc() "+
" define i int; "+
" let i = 0; "+
" end procedure; "
Statement stmt = conn.createStatement ();
stmt.execute (q);
q=" execute procedure runproc(); ";
stmt.execute (q);
Because maybe the driver failed to precompile your sql once, so that nothing happen. -
Calling Stored Procedure using J2EE (CMP/BMP)
Hi guys,
Can anyone please help me of how to call a stored procedure using a bean in J2EE? I am using Sybase as a database. I am not sure of how to call a stored procedure that is stored in the database server.
I have one more problem that I am getting in my application. I have 6 entity beans for 6 tables (3 temporary which are deleted and created as and when deployed and 3 permanent which are not deleted when deployed). When I access and manipulate data in temporary tables, everything works fine. But when I try to insert records in the 3 permanent tables, i get an error saying...
ejbexception.transactionrolledbackerror - Client's transaction rolledback
Your suggestions would be very valuable.
Thanks in advance,
ashishActually, I was getting the RolledBack exception before I was using stored procedure. The bean was supposed to make a few transactions in the tables within the Sybase database. Since it gave me rolledback error, I decided to write a stored proc. in the database and to call that procedure using the bean.
Now, I am not sure of how to call that procedure using the bean. Also, the syntax of calling that procedure using CallableStatement. I believe, I would have to use Bean Managed Persistence (BMP) if I want to use CallableStatement. I am fooling around with it right now and would let you know if I am getting any exceptions or errors. Meanwhile, any help on the syntax of calling the stored proc. would be highly appreciated.
Thanks in advance
Ashish -
Error while Executing stored procedure using ant
Hi,
I am trying to execute a stored procedure using ant ..
My build.xml is like this...
<project name="myproject" default="db.build">
<target name="db.build">
<sql driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@idm.orademo.com:1521:orcl"
userid="test"
password="oracle11g"
print="yes"
classpath="E:\\ojdbc14.jar"
src="E:\\upg_9102BP07.sql" />
<!--
<classpath>
<pathelement path=""\\>
<\\classpath> -->
</target>
</project>
I have my stored procedure in upg_9102BP07.sql as shown in above src..
When im executing ant cmd I got the following exception
E:\>ant -f test.xml
Buildfile: test.xml
db.build:
*[sql] Executing resource: E:\upg_9102BP07.sql*
*[sql] Failed to execute: declare cnt int*
BUILD FAILED
E:\test.xml:12: java.sql.SQLException: ORA-06550: line 1, column 15:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
*:= . ( @ % ; not null range default character*
Total time: 44 seconds
I have no clue.. But this sql ran successfully when did manually..
Please help me in solving the issue...
-- MariasHere is my script bit lengthy...
Rem
Rem $Header: oim/server/Database/Oracle/Upgrade/Release91x/910x/List/9102_ddl_AddcolumnToRCE_Oracle.sql st_oim_devjain_bug-9003841/1 2009/10/09 02:24:19 devjain Exp $
Rem
Rem 9102_ddl_AddcolumnToRCE_Oracle.sql
Rem
Rem Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
Rem
Rem NAME
Rem 9102_ddl_AddcolumnToRCE_Oracle.sql - <one-line expansion of the name>
Rem
Rem DESCRIPTION
Rem Create a new column 'RCE_DELETE' in RCE table
Rem
Rem MODIFIED (MM/DD/YY)
Rem blaksham 09/30/09 - Created
Rem
declare cnt int;
Begin
Select Count(1) into cnt From User_Tab_Columns Where TABLE_NAME='RCM' And COLUMN_NAME='RCM_DELETE';
IF cnt=0 Then
Begin
Execute Immediate 'ALTER TABLE RCM ADD RCM_DELETE VARCHAR2(1)';
End;
Else
DBMS_OUTPUT.PUT_LINE('Column already exists in the DB');
End IF;
End;
Rem
Rem $Header: oim/server/Database/Oracle/Upgrade/Release91x/910x/List/9102_dml_odf_source_name.sql st_oim_devjain_bug-9003841/1 2009/10/09 02:44:45 devjain Exp $
Rem
Rem 9103_dml_odf_source_name.sql
Rem
Rem Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
Rem
Rem NAME
Rem 9103_dml_odf_source_name.sql - <one-line expansion of the name>
Rem
Rem DESCRIPTION
Rem <short description of component this file declares/defines>
Rem
Rem NOTES
Rem <other useful comments, qualifications, etc.>
Rem
Rem MODIFIED (MM/DD/YY)
Rem vpotukuc 09/17/09 - Bug8796435: Increase the size of odf_source-name
Rem vpotukuc 09/17/09 - Created
Rem
SET ECHO ON
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 80
SET TRIMSPOOL ON
SET TAB OFF
SET PAGESIZE 100
declare
collen NUMBER := 0;
begin
select char_length into collen from user_tab_columns where table_name = 'ODF' and column_name = 'ODF_SOURCE_NAME';
IF (collen < 400) then
execute immediate 'alter table ODF modify ODF_SOURCE_NAME varchar2(400)';
END IF;
END;
File name: 91_dml_update_reviewers_With_NoEmail_attestation.sql
Purpose: Modify the email template to replace the 'Delegated By Last Name' with 'Reviewer Last Name' and 'Delegated By User Id' to 'Reviewer User Id'.
Author: Babu Lakshamanaiah
Description: Modify the email template 'Attestation Reviewers With No E-mail Addresses Defined'
declare
cnt int;
begin
Select Count(1) into cnt From emd Where emd_name='Attestation Reviewers With No E-mail Addresses Defined' and emd_language='en' and emd_country='US';
IF cnt=0 Then
Begin
DBMS_OUTPUT.PUT_LINE('There is no record with emd_name Attestation Reviewers With No E-mail Addresses Defined ');
End;
Else
update emd set emd_body='The following attestation reviewers do not have email addresses defined. Attestation requests have been generated for these reviewers and can be accessed by loging in to Oracle Identity Manager. However, notification emails were not sent.' ||chr(10) || chr(10) ||
'Attestation process: <Attestation Definition.Process Name>' || chr(10) ||
'Attestation Request ID: request <Attestation Request.Request Id>' || chr(10) ||
'Request date: <Attestation Request.Request Creation Date>' || chr(10) || chr(10) ||
'Reviewers Without E-mail Address: <reviewers> ' || chr(10) ||
'<Attestation Task.Reviewer First Name> <Attestation Task.Reviewer Last Name> [<Attestation Task.Reviewer User Id>]' Where emd_name='Attestation Reviewers With No E-mail Addresses Defined' and emd_language='en' and emd_country='US';
End IF;
commit;
end;
Please help me out.....
--Marias -
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 -
How to call stored procedures from java program?
I have tried to run a program that calls a stored procedure on MySQL
server version 5.0.17 by using connector/j 5.0, but it always fails on the
statement: con.preparecall() ,
have looked on the internet and found out that people can all mysql
stored procedure all right in their programs, really dont know what's
wrong with this small peiece of code:
import java.sql.*;
public class TestDB {
// procedure being called is:
CREATE PROCEDURE `dbsaystorm`.`getsite` ()
BEGIN
select name from tblsite;
END
public static void main(String[] args) {
try {
//Class.forName("org.gjt.mm.mysql.Driver");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/dbname",
"user", "pwd");
* executing SQL statement here gives perfect correct results:
// PreparedStatement ps = con.prepareStatement("select name from tblsite");
// ResultSet rs =ps.executeQuery();
// but in stored procedure way...
//it fails here on this prepare call statement:
CallableStatement proc = con.prepareCall("call getsite()");
ResultSet rs =proc.executeQuery();
if (rs == null) return;
while (rs.next()){
System.out.println("site name is: "+ rs.getString(1));
rs.close();
} catch (SQLException e) {e.printStackTrace();}
catch (Exception e) {e.printStackTrace();}
}it always gives this exception:
java.lang.NullPointerException
at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:959)
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1280)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3668)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:638)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:453)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4365)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4439)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4413)
at saystorm.server.data.database.TestDB.main(TestDB.java:29)
where have I gone wrong?
when I commented out the statement that makes the procedure call and call preparedstatement to execute SQL select statement, it gave perfectly correct result.
it looks like there is no problem with java prog accessing MYSQL server database, but the it seems that it's just java can't call stored procedure stored on the mysql server version 5.
can it or can't it? if it can, how is that accomplished?It is a bug in the driver because it shouldn't be
returning that exception (null pointer) even if you
are doing something wrong.
Are you using the latest version of the driver?
The stored procedure runs when you run it from the
gui/command line using a MySQL tool - correct?
As suggested you should be using the brackets. What
is the data type of the 'name' field?
You could try returning another value like one of the
following
select 1, name from tblsite;
select name, 1 from tblsite;
That might get around the bug
Additionally try just the following...
select 'test' from tblsite;yes, the driver used is in connector/j 5.0--the lastest one, and the
procedure can run correctedly at either command line or GUI mode
with no problem whatsoever, the returned data type is string type,
I have not got the chance to test it again with those values you
suggested, as I have abandoned the laptop I used to write that code
initately. There have been some other really weird cases happened on
that computer. I guess that must be something wrong with the JVM
installed on it, it was upgraded from jre5.0.04 to 06, and to 09.
something within hte JVM must have been messed up(the only reasonable
explanation). Because the same code runs correctly on my new laptop,
using the same environment: jvm 5.0_09, mysql 5.0.18, connector/J 5.0.
that old laptop really was a nightmare. -
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; -
Retrieving PL/SQL Table Type returned by stored procedure using Java.
Hi All,
I am facing an issue in a Stored Procedure (SP) which returns Table Type, the PL/SQL complex type.
Below mentioned is how my stored procedure looks like.
CREATE OR REPLACE package sp_test_pkg as
TYPE v_value_table_type is table of SW_VALID_CODE.swValue%Type
index by binary_integer;
v_swRMAStatus v_value_table_type;
procedure sp_test
(locale in int,
name in SW_CODE.swName%Type,
v_value_table out v_value_table_type,
batch_size in int,
out_batch_size in out int,
status out int);
end sp_test_lcode_code_pkg;
My java program to access this stored procedure is as given below:
import java.sql.*;
import oracle.jdbc.driver.*;
public class OracleTest {
public static void main(String args[]) {
Connection con = null;
OracleCallableStatement cstmt = null;
String url = "url";
String userName = "username";
String password = "password";
try
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
con = DriverManager.getConnection(url, userName, password);
cstmt = (OracleCallableStatement)con.prepareCall("begin " +
"sp_test_pkg.sp_test_pkg(?,?,?,?,?,?); end;");
cstmt.setInt(1, 1);
cstmt.setString(2, "Test");
cstmt.registerOutParameter(3, OracleTypes.ARRAY);
cstmt.setInt(4, 10);
cstmt.setInt(5, 1);
cstmt.registerOutParameter(5, Types.INTEGER);
cstmt.registerOutParameter(6, Types.INTEGER);
cstmt.execute();
} catch(Exception ex) {
ex.printStackTrace(System.err);
} finally {
if(cstmt != null) try{cstmt.close();}catch(Exception _ex){}
if(con != null) try{con.close();}catch(Exception _ex){}
When i execute this java program, i get the following error:
java.sql.SQLException: Parameter Type Conflict: sqlType=2003
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:187)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:229)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterBytes(OracleCallableStatement.java:245)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:389)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:452)
at OracleTest.main(OracleTest.java:49)
I am not sure where i am going wrong. I have never worked on such complex types before. I want to retrieve the complex table type returned by the stored procedure using my java source code.
Can anyone please help me out in resolving this issue?. This is very urgent.JDBC does not recognise types declared in PL/SQL. This is documented in the Dev Guide. [Find out more|http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/oraarr.htm#1057625].
The only work around would be to build a wrapper which calls your existing PL/SQL procedures and returns a SQL type instead. Obviously not knowing your precise scenario I have no idea how much work this entails for you. It may be worth building a code generator.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Curious thing while calling a procedure from Java !...
Hi !. My name is Agustin and my doubt would be the following one... I am working for a e-business comp and they asked me to call a procedure from java... The code is the following one:
CallableStatement cs = null;
System.out.println("Fecha Nro. 1: " + paramFechaDesde);
System.out.println("Fecha Nro. 2: " + paramFechaHasta);
try
cs = getDBTransaction().createCallableStatement("{call paq_w_ListadoSiniestralidadART. p_sinsiniest(?,?,?,?) }",0);
cs.registerOutParameter(4,OracleTypes.VARCHAR);
cs.setInt(1,paramContrato.intValue());
cs.setString(2,paramFechaDesde);
cs.setString(3,paramFechaHasta);
cs.setString(4,paramNombreArchivo);
cs.executeQuery();
String nomArchivo = cs.getString(4);
System.out.println("### " + nomArchivo +" ###");
catch(SQLException e)
The weird thing is that, I was expecting a big big exception but the only thing I got is
### Error ###
The String I am expecting is a file's name !; so I am a little bit confused...
Also I didn't know where to post so If it's in the wrong category... I apologize !... If anyone need more details, I'll be checking out... The account I am working on is an Insurance company, who is the one who provide access to the DB and the procedures... So I can't check what's inside...Please provide your Java and OS versions, the JDBC jar file and the Oracle DB version being used when you post.
>
I was expecting a big big exception
>
Then why do you have an empty exception block? That just makes it disappear so you won't see one if it happens.
And your code has
cs.registerOutParameter(4,OracleTypes.VARCHAR);
cs.setString(4,paramNombreArchivo);You use 'registerOutParameter' for an OUT parameter and the 'setXXX' methods for other parameters.
Remove the 'setSTring' for the OUT parameter.
Then as malcollmmc already said
>
Sounds like the PL/SQL is returning "Error" as the 4th parameter of the call
>
The actual value returned by PL/SQL is strictly determined by the PL/SQL code and Java and JDBC are not involved.
Fix the code problems, retest, and folllowup with whoever wrote the code if it still returns ERROR. -
Calling stored procedure via java
Hi all,
i have a problem calling a stored procedure in my java code. I found an example at OTN which seems not to be correct. I know there had been a lot of posting regarding this isue but i did not find the solution.
I had the following VB-code to translate to java:
Set k = Server.CreateObject("ADODB.command")
With k
.activeconnection = Db
.CommandType = 4
.CommandText = "Get_SK"
Set vret = .createparameter("vRet", 131, 2) 'Output
.Parameters.append vret
.Execute
End With
In my java code:
CallableStatement sproc_stmt = null;
try {
sproc_stmt = lsession.connection().prepareCall("{ ? = call TCSDBOWNER.Get_SK}");
sproc_stmt.registerOutParameter(1,OracleTypes.NUMERIC);
sproc_stmt.setFetchSize(10);
sproc_stmt.execute();
The call generates an id for inserting new rows in the DB. executing the code shown above i got the following error:
wrong number or types of parameter/arguments
Is there anybody who can help me? Best regards,
akHi again,
this was really ugly:
Re: Executing stored procedure via java
Thanks all, regards,
ak -
Exception while calling stored procedure in SQL server
Hi,
I run into a problem while calling a proc in SQL server. I am using a database control to do so. The proc returns a integer. This is the first time I use SQL server. Any thoughts? Thanks in advance.
My method call is:
int createAccount(SQLParameter[] param)
The sql is:
{call espsiCompany(?, ?, ?)}
The error is:
java.lang.NullPointerException
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1885)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2691)
at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:373)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:423)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:396)
at com.bea.wlw.runtime.jcs.container.JcsProxy.invoke(JcsProxy.java:388)
at services.OnyxDBControl.createAccount(OnyxDBControl.ctrl)
at services.OnyxDBControlTest.createAccount(OnyxDBControlTest.jws:18)Hi. That's not the signature of the procedure. What I'd like to see is
the SQL used to create the procedure, eg:
create procedure myProc @foo int, @bar varchar(30) ....
as
begin
end
Jun Li wrote:
Here you go. Thanks for your time.
DECLARE @RC int
DECLARE @iSiteId int
DECLARE @iCompanyId int
DECLARE @chLanguageCode char(4)
DECLARE @vchAssignedId varchar(255)
DECLARE @vchCompanyName varchar(255)
DECLARE @vchAddress1 varchar(255)
DECLARE @vchAddress2 varchar(255)
DECLARE @vchAddress3 varchar(255)
DECLARE @vchCity varchar(255)
DECLARE @chRegionCode char(4)
DECLARE @chCountryCode char(4)
DECLARE @vchPostCode varchar(40)
DECLARE @vchPhoneNumber varchar(40)
DECLARE @vchEmailAddress varchar(255)
DECLARE @vchURL varchar(255)
DECLARE @iCompanyTypeCode int
DECLARE @iCompanySubTypeCode int
DECLARE @iFamilyId int
DECLARE @iParentId int
DECLARE @iPrimaryContactId int
DECLARE @vchContactFirstName varchar(255)
DECLARE @vchContactLastName varchar(255)
DECLARE @iDivisionCode int
DECLARE @iSICCode int
DECLARE @iMarketSector int
DECLARE @vchTaxId varchar(255)
DECLARE @vchDunnsNumber varchar(255)
DECLARE @iPhoneTypeId int
DECLARE @iAddressTypeId int
DECLARE @iSourceId int
DECLARE @iStatusId int
DECLARE @bValidAddress tinyint
DECLARE @iAccessCode int
DECLARE @bPrivate tinyint
DECLARE @vchUser1 varchar(255)
DECLARE @vchUser2 varchar(255)
DECLARE @vchUser3 varchar(255)
DECLARE @vchUser4 varchar(255)
DECLARE @vchUser5 varchar(255)
DECLARE @vchUser6 varchar(255)
DECLARE @vchUser7 varchar(255)
DECLARE @vchUser8 varchar(255)
DECLARE @vchUser9 varchar(255)
DECLARE @vchUser10 varchar(255)
DECLARE @chInsertBy char(10)
DECLARE @dtInsertDate datetime
DECLARE @tiLockRecord tinyint
DECLARE @tiRecordStatus tinyint
DECLARE @tireturnType tinyint
-- Set parameter values
EXEC @RC = [ONYXPROD].[dbo].[espsiCompany] @iSiteId, @iCompanyId OUTPUT , @chLanguageCode, @vchAssignedId, @vchCompanyName, @vchAddress1, @vchAddress2, @vchAddress3, @vchCity, @chRegionCode, @chCountryCode, @vchPostCode, @vchPhoneNumber, @vchEmailAddress, @vchURL, @iCompanyTypeCode, @iCompanySubTypeCode, @iFamilyId, @iParentId, @iPrimaryContactId, @vchContactFirstName, @vchContactLastName, @iDivisionCode, @iSICCode, @iMarketSector, @vchTaxId, @vchDunnsNumber, @iPhoneTypeId, @iAddressTypeId, @iSourceId, @iStatusId, @bValidAddress, @iAccessCode, @bPrivate, @vchUser1, @vchUser2, @vchUser3, @vchUser4, @vchUser5, @vchUser6, @vchUser7, @vchUser8, @vchUser9, @vchUser10, @chInsertBy, @dtInsertDate, @tiLockRecord, @tiRecordStatus, @tireturnType
Maybe you are looking for
-
Hi, I am not able to run a simple and empty UICell in JDeveloper. Steps: 1.Create a new UICell by including ApplCore jars in JDev on Linux environment. 2.Right click on this cell and run it. 3.I can able to see some exceptions in Log file of JDev too
-
How can you get wmv etc to play on imac? thank you
I have worked it out for iPad, but am wondering if ther is any application that I need so that I can watch wmv etc on iMac. thank you!
-
Unable to UNZIP file...
Hi All, I downloaded the UNZIP utility on update.oracle.com and getting this error: EM12c]$ unzip_lnx -t em12_linux_x86_disk1of2.zip unzip: cannot find em12_linux_x86_disk1of2.zip, em12_linux_x86_disk1of2.zip.zip or em12_linux_x86_disk1of2.zip.ZIP. a
-
No connection pool with oracle thin driver
Hi all, whenever I try to set up my server as target for an Oracle connection pool on OPracle 8.1.7, I get the following exception: java.sql.SQLException: Illegal Arguments at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168) at oracle
-
Two problems, the typing on top of itself and as listed above.