Calling a stored procedure or ioracle 8 from java
hello,
i made a stored procedure as below in 1 program :
String url = "jdbc:odbc:rjc1";
Connection con = DriverManager.getConnection(url,"scott","tiger");
Statement stmt = con.createStatement();
String createProc =
"Create procedure sp1 as select * from items order by iprice desc";
stmt.executeUpdate(createProc);
in other program i have a code as below to retrieve the result of stored procedure :
CallableStatement cs = con.prepareCall("{call sp2}");
ResultSet rs = cs.executeQuery();
the error message that i get is SCOTT.SPa is invalid.
any help would be great.
thanx in advance.
this might be a silly answer, but i donot see any SPa in ur code????
Similar Messages
-
Calling stored procedures in Sybase from java
Hi,
I am using the following stored procedure in Sybase
use xyzdb
go
-- drop procedure if it already exist
if object_id('up_name_select') is not null
begin
drop procedure up_name_select
end
go
create procedure up_name_select
@zid numeric(7,0),
@firstname char(40),
@lastname char(40)
as
select zid,
firstname,
lastname
from name
where zid = @zid or
(lastname like @lastname or firstname like @firstname)
go
-- update documentation records in object_docs
delete object_docs
from object_docs
where object_name = "up_name_select"
go
insert into object_docs values("up_name_select","Selects records from the name table based upon the values of the input parameters.")
go
-- update documentation records in column_docs
delete column_docs
from column_docs
where object_name = "up_name_select"
go
insert into column_docs values("up_name_select","@zid","System generated ID for an individual contact.")
insert into column_docs values("up_name_select","@firstname","First name of the contact. SQL wild card characters are accepted.")
insert into column_docs values("up_name_select","@lastname","Last name of the contact. SQL wild card characters are accepted.")
go
-- print success message and grant permissions
if object_id('up_name_select') is not null
begin
print "Procedure up_name_select created."
grant execute on up_name_select to developer_role
end
go
This stored procedure selects the values from the table "name" for a given where condition (if I am not wrong).
Can any one give me sample java code to select the records from the table "name" for a given zid.
Thankyou in advance.
Regards
sgatl2calling stored procedures from java
here is the sample code
CallableStatement cs = con.prepareCall("{call selectlogin (?)}");
cs.setString (1, "value");
ResultSet rs = cs.executeQuery ();
while (rs.next ())
//your code for display
} more on gooooooogle
http://www.google.com/search?q=calling+stored+procedures+from+java+with+sample+example&client=netscape-pp&rls=com.netscape:en-US -
To call db2 stored procedure having parameters in java application
Hi,
I've created db2 stored procedure which is running perfectly on db2 server after giving a CALL to it. But when I tried to call this same stored procedure in java application, its reflecting with following error......
com.ibm.db2.jcc.b.SqlException: [jcc][10100][10910][3.50.152] java.sql.CallableStatement.executeQuery() was called but no result set was returned.
Use java.sql.CallableStatement.executeUpdate() for non-queries. ERRORCODE=-4476, SQLSTATE=null
at com.ibm.db2.jcc.b.wc.a(wc.java:55)
at com.ibm.db2.jcc.b.wc.a(wc.java:102)
at com.ibm.db2.jcc.b.tk.b(tk.java:575)
at com.ibm.db2.jcc.b.vk.yb(vk.java:136)
at com.ibm.db2.jcc.b.vk.executeQuery(vk.java:114)
at SPApplication.main(SPApplication.java:31)
Here is the code.......
import java.sql.*; public class SPApplication { public static Connection con; public static CallableStatement proc_stmt; public static ResultSet rs; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { Class.forName("DB2 DRIVER CLASS"); System.out.println("Class loaded....."); con = DriverManager.getConnection("jdbc:db2://localhost:PORTNO/" + " DatabaseName", "username", "password"); System.out.println("Connection established....."); proc_stmt = con.prepareCall("call procedure_name(?)"); //IN Parameter proc_stmt.setInt(1, 5); System.out.println("Called procedure....."); rs = proc_stmt.executeQuery(); /******** THIS IS LINE NO. 31 *********/ while (rs.next()) { // Fetching rows one by one over here } proc_stmt.close(); rs.close(); con.close(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); } catch (SQLException sqle) { sqle.printStackTrace(); } finally { /* try { proc_stmt.close(); rs.close(); con.close(); } catch (SQLException sqle) { sqle.printStackTrace(); } */ } } }
Please correct me, if I am wrong at any point in my application..
I would really appreciate for resolving my problem.
Thanks,
Manasi N.Hi jschell ,
Firstly, I tried out with execute() and getMoreResults() to check if the statement is returning result set. - Its returning "null" only.
Secondly, I tried with following one by one :
1. Find a new jdbc driver
2. Write a different stored procedure.I am using DB2 Express edition - DB2 v9.7.0.0
I have the required jar files - i)db2jcc.jar ii) db2jcc_license_cu.jar
From these I found the available jdbc drivers as -
i) com.ibm.db2.jcc.DB2Driver
ii) COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver
iii) com.ibm.db2.jcc.uw.DB2StoredProcDriver
I tried out my code by using each of these drivers, but still returning result set as null.
Moreover, I changed my stored procedure which has cursor returning result set. In this case also, result set is null.
Code snippet for this SP is -
30 Class.forName("com.ibm.db2.jcc.uw.DB2StoredProcDriver");
31 System.out.println("Class loaded....");
32 con = DriverManager.getConnection
33 ("jdbc:db2://localhost:portno/dbName", "user", "password");
34 System.out.println("Connection established....");
35
36 proc_stmt = con.prepareCall("call javaSP()");
37
38 System.out.println("Called stored procedure....");
39
40 proc_stmt.execute();
41 //proc_stmt.executeUpdate();
42 //rs = proc_stmt.getResultSet();
43
44 System.out.println("Query executed....");
45
46 if ((proc_stmt.getMoreResults() == false) &&
47 (proc_stmt.getUpdateCount() == -1)) {
48 System.out.println("No more result sets");
49 }o/p is (for every mentioned above jdbc driver) :-
Class loaded....
Connection established....
Called stored procedure....
Query executed....
No more result sets..
The o/p is always "No more result sets"
What else can be tried out to retrieve the result set from stored procedure from Java application? And the most important, these same stored procedures are returning result sets on db2 server after calling them.
Thank you,
Manasi.N
Edited by: Manasi.N on Apr 14, 2010 12:27 AM
Edited by: Manasi.N on Apr 14, 2010 12:28 AM -
Calling DB2 Stored procedure(with parameters) from powershell
Hi
I am trying to call a DB2 stored procedure that has parameters from Powershell scrip and I am not able to can some one help me here?
$ServerName = 'XXXX'
$dbalias='XXXXX'
$conn_string = "Provider=IBMDADB2;DBALIAS=$dbalias;Uid=;Pwd=;"
$conn = new-Object system.data.Oledb.OleDbconnection
$conn.ConnectionString = $conn_string
$conn.open()
$query="CALL DBID_CONTROL.GET_TABLE_MAINT_CTL(?,?,?,'MSAS','DATABASE_CONNECTIONS_CUBE','CUBE_PARTITION');"
$cmd = new-Object system.data.Oledb.OleDbcommand($query,$conn)
$ds=New-Object system.Data.DataSet
$da=New-Object System.Data.OleDb.OleDbDataAdapter($cmd)
$da.Fill($ds) [int]$cur_utc_date_key = $ds.Tables[0].Rows[0][0]
$cur_utc_date = $ds.Tables[0].Rows[0][1]
###list current date key & current date values
write-output "current date key value is $cur_utc_date_key"
write-output "current date value is $cur_utc_date"
write-output " "
ThanksHi
This is the error message i get when i run the script
Exception calling "Fill" with "1" argument(s): " CLI0100E Wrong number of parameters. SQLSTATE=07001"
At line:45 char:10
+ $da.Fill <<<< ($ds)
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : DotNetMethodException -
Problem Calling MaxDB stored procedure with output from MII Query template
Hi,
I am using Max DB Database studio to write stored procedure, I am calling stored procedure from MII Query using CALL statement.
Can anyone guide me how to pass output values of stored procedure.
Examlpe::
call ProcName('[Param.1]','[Param.2]','[Param.3]','[Param.4]','[Param.5]', :isSuccess, :Trace)
In the above line of code I am not able to get the output values of stored procedure that is isSuccess and Trace values in Query template when executed. But same thing I get when executed in Database studio.
How do I call with outputs for any stored procedure in MII.
Any help would be appriciated.
Thanks,
PadmaMy call statement is like this
call RESULTDATA_INSERT('[Param.1]','[Param.2]','[Param.3]', :isSuccess, :Trace)
I am able to insert record in DB, But I am not getting output values in Query template.I have done this in Fixed Query, when I execute it throws me "Fatal error as Loaded content empty".
I tried giving select below call but it dont work.
Regards,
Rao -
Passing of ResultSet to Stored Procedure(Oracle 8i) from Java
My requirement is such that I want to send a resultset to a stored procedure(In oracle8i). Through Java API's.
The input parameter to the PLSQL is a ref cursor.
I am trying to send the resultSet using CallableStatement of java but it is throwing an Inavlid column type error.
So firstly is it possible to send a resultset to Oracle through java. If yes, then please suggest me as to how it can be done?Rajeev,
I remember seeing something on Oracle's MetaLink Web site, saying that this is not supported. Sorry, but I can't give you any more details -- I don't remember (and I'm too lazy to look :-)
I also think that I found that MetaLink article via a posting to one of these (i.e. Oracle) forums. Perhaps a search of the forum archives will help?
Good Luck,
Avi. -
Call Oracle Stored Procedure with Parameters from Windows Batch File
Hi,
I have an oracle procedure that requires two parameters to execute, start date and end date as such:
CREATE OR REPLACE PROCEDURE insert_orders(
pSTART_DT IN varchar2
, pEND_DT IN varchar2
I want to create a windows batch file to execute the procedure but want to be able to specify the parameters (ie start and end dates) in the batch file as opposed to changing the sql file that the batch file uses to execute the procedure but I don't know what the syntax is. I tried the following but it still doesn't work.
Sql File: call_insert_orders.sql
execute insert_orders('&1','&2');
exit
Batch File:
sqlplus username/password @call_insert_orders.sql %01-jan-2010% %01-jan-2011%
When I execute the batch file, my DOS window still prompts me to enter value 1 so I think it recognizes that there is a variable being used but is not able to fill in the actual value I specify. I'm not an experienced DOS/Windows Batch File person so I'm guessing it's my syntax that's screwed up. There is not a lot of documentation on this subject matter hence my post on this forum. Any helps would be appreciated.
ThanksHello,
Just try the same DOS command without all the % sign.
In MS-DOS, the % at the beginning and at the end of a string are for variables. Which means your batch is looking for a variable called 01-jan-2010 and a variable called 01-jan-2011, but those are the values you want to pass, not the name of variables.
As they are not defined, nothing is passed to the sqlplus script, and that is why you are prompted for values.
Hope it will help.
Regards,
Sylvie -
Without calling stored procedure or functions from database
Hi,
I am using Jdeveloper 11.1.1.5.0.
=>How to do PL/SQL procedures and functions in ADF without calling stored procedure or function from DB?S, PL/SQL procedures and functions are done in Application Module class or in managed bean..By calling the stored procedures or functions from DB.
But I am asking how to do if DB doesn't have any procedures,triggers and functions. -
Calling SQL Stored Procedure using Oracle Gateway
Hi
Do you know how i can call a stored procedure with parameters from Oracle using oracle gateway?Don't know which gateway you are using. Only the transparent gateway for SQL Server and Sybase that have support for stored procedures.
Take a look at case 7 which shows how to do this.
Rem case7.sql
Rem
Rem Copyright (c) Oracle Corporation 2000. All Rights Reserved.
Rem
Rem NAME
Rem case7.sql
Rem
Rem DESCRIPTION
Rem SQL script which executes the demo case7 for the
Rem Transparent Gateways
Rem
Rem NOTES
Rem The database link GTWLINK should be created before you can
Rem run this demo file
Rem
Rem MODIFIED (MM/DD/YY)
Rem kpeyetti 11/09/00 - Created
Rem
SET ECHO ON
DROP TABLE LOCAL_GTW_DEPT;
CREATE TABLE LOCAL_GTW_DEPT (DEPTNO INTEGER, DEPTNAME VARCHAR2(14));
SELECT * FROM LOCAL_GTW_DEPT;
DECLARE
DNAME VARCHAR2(14);
BEGIN
"GetDept"@GTWLINK(10,DNAME);
INSERT INTO LOCAL_GTW_DEPT VALUES (10, DNAME);
END;
SELECT * FROM LOCAL_GTW_DEPT; -
Calling Oracle stored procedure from java
The following query calls a stored procedure TRANSLATE_ZONEPATH_ID defined in a package MT by the user MTDBA. currentZone is a member variable of the class, and currently has value 1
This query works just fine when I run it from SQLPlus* connected as MTDBA.
But from java, the following piece throws exception saying "invalid column name"
String query = "SELECT MTDBA.MT.TRANSLATE_ZONEPATH_ID('"+currentZone+"') "
+ "FROM DUAL ";
try
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery(query);
if (rst.next())
fullName = rst.getString(1);
stmt.close();
Anyone got any clue ?I always use CallableStatement to execute a stored procedure or function in a database (Oracle).
try this:
<code>
CallableStatement cs = dbConnection.prepareCall("{ ? =
MTDBA.MT.TRANSLATE_ZONEPATH_ID(?)}");
cs.setString(1, currentZone);
cs.registerOutParameter(1, Types.VARCHAR);
cs.executeUpdate();
fullname = cs.getString(1);
cs.close();
</code>
There is also a jdbc forum, where your should post this kind of problem :-)
Hope this help's
ThK -
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 -
Calling invalid stored procedure from java
Will the stored procedure which is invalid get re-compiled automatically when called from a java program?
1.a stored procedure is invalid (oracle 9i)
2.calling the stored procedure from a java program
3.what will happen a.oracle recompiles the stored procedure
b.returns an sql exception
what happens,kindly help
drop your mail to [email protected]
Keep Smiling and Mailing,
Vijay Anand Natesan.thank you ..Kindly let me know if any of your friends have tried this
-
How to call a stored procedure from WorkShop
Hello Everyone .. I'm quite new with WebLogic 8.1 & WorkShop, so please bare with
me .. Today I'm simply trying to find out how to call a stored procedure from
within workshop, using any of the DB Controls .. I see workshop provides a way
create a Java Control, Rowset Control, but it wont easily allow for a stored procedured
to be entered in place of the inline query .. Perhaps I've over looked it. Any
advise on the best way to tackle this task will be appreciated.
AtahualpaAtahualpa--
Maybe this will help:
http://edocs.bea.com/workshop/docs81/doc/en/workshop/guide/controls/database/conStoredProcedures.html
Eddie
Atahualpa wrote:
Hello Everyone .. I'm quite new with WebLogic 8.1 & WorkShop, so please bare with
me .. Today I'm simply trying to find out how to call a stored procedure from
within workshop, using any of the DB Controls .. I see workshop provides a way
create a Java Control, Rowset Control, but it wont easily allow for a stored procedured
to be entered in place of the inline query .. Perhaps I've over looked it. Any
advise on the best way to tackle this task will be appreciated.
Atahualpa -
Calling a stored procedure from within a ViewObject
Is it possible to make stored procedure call from within a BC4J ViewObject? Basically something like this:
select * from table(f1(3)); where f1 is a table function. Using Oracle's pipelined table functions?
If not, is it possible to call a stored procedure from Java and have the returned results be put back into a BC4J RowSet.
In addition, is there a way to create a JDBC Resultset from a BC4J RowSet?
We need to be able to dynamically create our SQL statements (the entire SQL, not just the where clause) but are required to have these sql statements generated/executed from within a pl/sql stored procedure in the database.Is it possible to make stored procedure call from within a BC4J ViewObject? Basically something like this:
select * from table(f1(3)); where f1 is a table function. Using Oracle's pipelined table functions?
Yes. Using our expert-mode query feature this is possible.
is it possible to call a stored procedure from Java and have the returned results be put back into a BC4J RowSet.
Yes. See this article about basing a view object on a REF CURSOR:
http://radio.weblogs.com/0118231/2003/03/03.html
In addition, is there a way to create a JDBC Resultset from a BC4J RowSet?
No. Not directly. What's the business requirement here so I can understand better?
We need to be able to dynamically create our SQL statements (the entire SQL, not just the where clause) but are required to have these sql statements generated/executed from within a pl/sql stored procedure in the database.
REF CURSOR would work fine, or if it's just the statement that needs to be generated dynamically, you could fetch the text of the SQL statement from the stored procedure, then use createViewObjectFromQueryStmt(). Although this has runtime overhead involved with describing the query.
The REF CURSOR based approach is probably best for this. -
Errors in calling Oracle stored procedure using java CallableStatement
Hello,
I have an oracle stored procedure below, it has been tested in PL/SQL without errors. During testing, in_c_file_type="F"; out_n_seqno_freeformat=120139596 and out_n_seqno_commaseprated is null (empty in value column).
When I run the program in Eclipse (windows xp), error messages is below: (It stopped at line 'cstme.execute();' )
Message:ORA-06550: line 1, column 26: PLS-00103: Encountered the symbol "" when expecting one of the following: . ( ) , * @ % & | = - + < / > at in is mod remainder not range rem => .. <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ as between from using || indicator multiset member SUBMULTISET_ The symbol ", was inserted before "" to continue. Error code:6550 SQL statement:65000 {code} Does anyone know what cause the error? It seems like something is missing in the stored procedure. But the stored procedure passes the test in the PL/SQL. The oracla driver I used is Oracle thin driver. Oracle version is 10.2.g Thanks in advance. northcloud {code} create or replace procedure SP_GET_SEQNO_2( in_c_file_type in char, out_n_seqno_freeformat out integer, out_n_seqno_commaseprated out integer) is n_seqno_commaseprated integer; n_seqno_freeformat integer; begin if in_c_file_type ='F' THEN SELECT message_counter.nextval INTO n_seqno_freeformat FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_freeformat,empty_clob(),empty_clob()); elsif in_c_file_type ='C' THEN SELECT message_counter.nextval INTO n_seqno_commaseprated FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_commaseprated,empty_clob(),empty_clob()); else SELECT message_counter.nextval INTO n_seqno_freeformat FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_freeformat,empty_clob(),empty_clob()); SELECT message_counter.nextval INTO n_seqno_commaseprated FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_commaseprated,empty_clob(),empty_clob()); end if; out_n_seqno_freeformat := n_seqno_freeformat; out_n_seqno_commaseprated := n_seqno_commaseprated; end SP_GET_SEQNO_2; {code} ----- A part of java code I used to call the stored procedure is here. {code} String escapeString = "{call SP_GET_SEQNO_2 (? ? ?)}"; CallableStatement cstme = null; try { cstme = con.prepareCall(escapeString); cstme.setString(1, "F"); cstme.registerOutParameter(2, java.sql.Types.INTEGER); cstme.registerOutParameter(3, java.sql.Types.INTEGER); cstme.execute(); int seqNoFreeformat=0, seqNocommasepreted=0; seqNoFreeformat = cstme.getInt(2); seqNocommasepreted = cstme.getInt(3); System.out.println ("In ConvertXML.processStoredProcedure(), seqNoFreeformat= "+seqNoFreeformat+";seqNocommasepreted="+seqNocommasepreted); } catch (SQLException e) { //System.out.println ("In ConvertXML.processStoredProcedure(), SQLException: "+e); System.err.println("Message:"+e.getMessage()); System.err.println("Error code:"+e.getErrorCode()); System.err.println("SQL statement:"+e.getSQLState()); log.log(Level.INFO, log.getName() + " - SQLException : "+e); } {code}es5f2000 wrote:
jschell wrote:
That works?I dunno. The below definitely works, but like I said, I've only
ever done it with one output parameter (and that has always
been a ResultSet).
String callableQuery = "{?= call my_package.my_call(?, ?)}"
Yes I have done that and at least in terms of my code it wasn't just a result set.
But not with two.
Maybe you are looking for
-
I have an Ipod touch and recently added new music to my Itunes library. When I sync with the library, the new music does not show up on my ipod. The sync process seems to be working and there is still plenty of space on the Ipod for new music so I'm
-
How to fetch PO item delivery address from ME23n
Dear Experts, From ME23n, I have to fetch the delivery address for the po items ( at item level). This is mentioned in the 'Delivery Address' tab at item level details. I think this is the plant address, but if the user goes to ME22n and delib
-
Where is open links in new tab option as I dont want to right click?
I am using kubuntu 12.04 Fire fox 20. I want to open links in a new tab without right clicking I used to be able to this why can't I now?
-
hi, all I want to display the smartforms as pdf in web dynpro abap, bu there are error at runtime. Source code: method DISPLAYFORM . data : l_x(1) value 'X'. data: lv_text type char3, lv_syucomm type char1, ls_pdf type xstring, lv_fm_name
-
UNABLE TO CAST OBJECT OF TYPE 'PROFILECOMMON' TO TYPE 'PROFILECOMMON'
I have four web application configured on the IIS with .Net Framework 2.0 All the applications are working fine except one. If the system / server, restarted. The Application throws an error message "UNABLE TO CAST OBJECT OF TYPE 'PROFILECOMMON' TO T