CallableStatament for selection stored procedure

hello,
i write a jsp page where there are inputs. when i click on a button i want to search elements in my sql server database. to do that, i call a stored procedure :
CREATE PROCEDURE PS_ELTS
@param0 VARCHAR(40),
@param1 VARCHAR(10),
@param2 VARCHAR(6),
@param3 VARCHAR(6),
@param4 VARCHAR(40)
AS
SELECT ELTS.NAME,
ELTS.TEL,
ELTS.ADR1,
ELTS.ADR2,
ELTS.SERV
FROM ELTS
WHERE (ELTS.NAME LIKE @param0 OR @param0 IS NULL)
AND (ELTS.TEL LIKE @param1 OR @param1 IS NULL)
AND (ELTS.ADR1 LIKE @param2 OR @param2 IS NULL)
AND (ELTS.ADR2 LIKE @param3 OR @param3 IS NULL)
AND (ELTS.SERV LIKE @param4 OR @param4 IS NULL)
ORDER BY ELTS.NAME, ELTS.TEL
i have a java class elts as business object. in the class, there is a method search which takes an elts event, connects to the database and gets elements which are ok. if all parameters are null, i get every lines of ELTS table. it's ok. if one or more of the parametre is not null, i don't get any line. this is the method :
public void search(UtilBean bean) throws Exception {
int i = 0;
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, login, password);
if (connection != null) {
connectionOk = true;
this.setNAME(beanrecherche.getNAME());
this.setTEL(beanrecherche.getTEL());
this.setADR1(beanrecherche.getADR1());
this.setADR2(beanrecherche.getADR2());
this.setSERV(beanrecherche.getSERV());
String aProc = "{call PS_ELTS(?,?,?,?,?)}";
CallableStatement aStatement = connection.prepareCall(aProc);
aStatement.setString(1, fmt_sqlChaineLike(this.getNAME()));
aStatement.setString(2, fmt_sqlChaineLike(this.getTEL()));
aStatement.setString(3, fmt_sqlChaineLike(this.getADR1()));
aStatement.setString(4, fmt_sqlChaineLike(this.getADR2()));
aStatement.setString(5, fmt_sqlChaineLike(this.getSERV()));
aStatement.execute();
ResultSet rs = aStatement.getResultSet();
while (rs.next()) {
     i++;
UtilBean util = new UtilBean();
util.setNAME(rs.getString("NAME"));
util.setTEL(rs.getString("TEL"));
util.setADR1(rs.getString("ADR1"));
util.setADR2(rs.getString("ADR2"));
util.setSERV(rs.getString("SERV"));
listUtil.add(util);
do i do something wrong ? is there a solution to this problem ?

i found what's wrong. in my stored procedure, i defined parameters like this :
@param0 VARCHAR(40),
@param1 VARCHAR(10),
@param2 VARCHAR(6),
@param3 VARCHAR(6),
@param4 VARCHAR(40)
when i use :
aStatement.setString(1, this.getNAME());
java sends a 40 characters long string to the stored procedure so if i write 'hello', the stored procedure gets 'hello '. any element is like that in the database so i must change the stored procedure :
(ELTS.NAME LIKE @param0 OR @param0 IS NULL) became (ELTS.NAME LIKE rtrim(ltrim(@param0)) OR @param0 IS NULL)

Similar Messages

  • Creation of DB Adaptert for calling stored procedure in MS SQL server

    Hi,
    I need to create a DB adapter to call a stored procedure in MS SQL Server.
    I have gone thru the thread MS SQL Server database connection
    It mentions that we need to use a command line utility for generating the wsdl and xsd for calling stored procedures in MS SQL server. Please provide information where to find this utility and how to use it.
    Any links to tutorials are welcome.
    Thanks !!.
    Silas.

    Command line is required for stored procedures, if you are using the basic options you don't need to worry.
    (1) Download MS SQL Server 2005 JDBC Driver from Microsoft Site. http://msdn.microsoft.com/en-us/data/aa937724.aspx
    (2) The download is self extracting exe file. Extract this into Program Files on your machine. It should create folder as "Microsoft SQL Server 2005 JDBC Driver"
    (3) In above mentioned folder search for sqljdbc.jar copy this file into JDeveloper\JDBC\lib folder.
    (4) Open JDeveloper/jdev/bin/jdev.conf file add following entry.
    AddJavaLibPath C:/Program files/Microsoft SQL Server 2000 Driver for JDBC/lib
    While executing this step make sure that your JDeveloper is closed.
    (5) On command prompt go to J Developer folder and execute following command
    jdev -verbose
    This will open JDeveloper.
    (6) Now go to JDeveloper > Connections > Database Connections > New Database Connection
    (7) Select Third Party JDBC
    (8) Specify MS Sql Server User Name, password and Role.
    (9) In connection page specify following
    - Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
    - For class path browse to C:/Program files/Microsoft SQL Server 2000 Driver for JDBC/lib folder, select sqljdbc.jar add it as library.
    - Specify URL as following.
    jdbc:sqlserver://SERVERNAME:1433;databaseName=MSSQLDBNAME;
    (10) Go to Test page and test it.
    cheers
    James

  • Error message for running stored procedure

    Hello expert,
    I got error message for a stored procedure running as follows, will you please tell me what that error is? what is the reason for that error? appreciate very much.
    Job name=PROD DWH REPORT MART LOAD.1
    Job owner=DEVTEAM
    Job type=SQL Script
    Job status=Error
    Occurred At=Aug 9, 2011 5:26:29 AM EDT
    Target Name=proddw(Database Instance)
    Job output=
    Command:Output Log
    SQL*Plus: Release 10.2.0.3.0 - Production on Tue Aug 9 03:00:07 2011
    Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
    SQL> SQL> SQL> SQL> Connected.
    SQL> SQL> SQL> SQL> SQL> SQL>
    TO_CHAR(SYSDATE,'DD-
    09-aug-2011 03:00:07
    SQL> SQL>
    Many Thanks,

    What error? I can't see an error.

  • How to get list of parameters or arguments for a stored procedure

    Hi,
    Is there a way we can get the list of arguments or parameters for a stored procedure through Data Dictionary?
    I mean the way oracle has Meta Data tables like user_tables/dba_tables, user_triggers/dba_triggers through which we can get information about tables, triggers etc, in the same way is there a way in oracle so that we can get information about a procedure like what kind of arguments need to be passed, are they IN or OUT parameters, and what is their Data Types?
    I could find there is one View dba_procedures, but it does not give any information about the arguments a procedure takes.
    Thanks,
    Makrand
    Thansk

    or
    SQL> desc Raisesal ;
    PROCEDURE Raisesal
    Argument Name                  Type                    In/Out Default?
    ID                             NUMBER(4)               IN
    PERCENT                        NUMBER                  IN

  • Need sample source code for calling stored procedure in Oracle

    Hi.
    I try to call stored procedure in oracle using JCA JDBC.
    Anybody have sample source code for that ?
    Regards, Arnold.

    Thank you very much for a very quick reply. It worked, but I have an extended problem for which I would like to have a solution. Thank you very much in advance for your help. The problem is described below.
    I have the Procedure defined as below in the SFCS1 package body
    Procedure Company_Selection(O_Cursor IN OUT T_Cursor)
    BEGIN
    Open O_Cursor FOR
    SELECT CompanyId, CompanyName
    FROM Company
    WHERE CompanyProvince IN ('AL','AK');
    END Company_Selection;
    In the Oracle Forms, I have a datablock based on the above stored procedure. When I execute the form and from the menu if I click on Execute Query the data block gets filled up with data (The datablock is configured to display 10 items as a tabular form).
    At this point in time, I want to automate the process of displaying the data, hence I created a button and from there I want to call this stored procedure. So, in the button trigger I have the following statements
    DECLARE
    A SFCS1.T_Cursor;
    BEGIN
    SFCS1.Company_Selection(A);
    go_Block ('Block36');
    The cursor goes to the corresponding block, but does not display any data. Can you tell me how to get the data displayed. In the future versions, I'm planning to put variables in the WHERE clause.

  • Syntax for calling Stored procedures?

    Seems straightforward but I just can get the syntax.
    Here's the procedure defined in SQL
    CREATE Procedure usp_InsTest
    @title varchar(150),
    @length int,
    @catid int,
    @date datetime,
    @filename varchar(50),
    @typeid int,
    @desc varchar(2000),
    @statusid int,
    @assign char(1),
    @languageid int = null
    as
    Insert into test(TestTitle,TestLength,TestCatID,TestDate,TestFileName,
    TestTypeID,TestDesc,TestStatusID,TestIsAssigned,
    TestLanguageID)
    values (@title,@length,@catid,@date,@filename,@typeid,@desc,
    @statusid,@assign,@languageid)
    GO
    I have tried a number of ways. What is the correct sytax for calling a stored procedure with variables?

    Here's what I've come up with...
    Connection dbConn;
    Driver d = (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    String URL = "jdbc:odbc:" + "cms";
    dbConn = DriverManager.getConnection(URL, "sa", "");
    CallableStatement s;
    String x = "{call usp_InsTest(@title,@length,@catid,@date,@filename,@typeid,@desc,@statusid,@assign,@languageid)}";
    Calendar c = Calendar.getInstance();
    s = dbConn.prepareCall(x);
    s.setString(1,TestTitle);
    s.setInt(2,Integer.parseInt(TestLength));
    s.setInt(3,6);
    s.setDate(4,new java.sql.Date(System.currentTimeMillis()));
    s.setString(5,TestFileName);
    s.setInt(6,Integer.parseInt(TestTypeID));
    s.setString(7,"Test Description");
    s.setInt(8,Integer.parseInt(TestStatusID));
    s.setInt(9,Integer.parseInt(TestIsAssigned));
    s.setInt(10,1);
    ResultSet r = s.executeQuery();
    I get
    java.lang.NullPointerException
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setChar(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setString(Unknown Source)
    at CMSBatch.addToDatabase(CMSBatch.java:242)
    at CMSBatch.actionPerformed(CMSBatch.java:312)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    Line 242 is the first setString.
    Is my prepareCall statement correct?

  • Unable to Grant execute permissoin for all Stored Procedures.

    Hi,
    We have a DB called ABC, which has two schema of it ABC_DEV and ABCR1.
    there are 2 login users (userdev for ABC_DEV) and (userR1 for ABCR1).
    I careated a package and some stored procedure with userR1 for schema ABCR1.
    Now I want these package and stored procedures to be available for execution for userdev.
    How to do this usegin Oracle SQL Developer.
    Thanks in Advance

    Connect as ABCR1, or any other user that has GRANT EXECUTE privilege with the ADMIN option on the objects in the schema and select the object in the connections tab and right-click on it, select grant and then select the appropriate user and privilege.
    Chris

  • Best practice for calling stored procedures as target

    The scenario is this:
    1) Source is from a file or oracle table
    2) Target will always be oracle pl/sql stored procedures which do the insert or update (APIs).
    3) Each failure from the stored procedure must log an error so the user can re-submit the corrected file for those error records
    There is no option to create an E$ table, since there is no control option for the flow around procedures.
    Is there a best practice around moving data into Oracle via procedures? In Oracle EBS, many of the interfaces are pure stored procs and not batch interface tables. I am concerned that I must build dozens of custom error tables around these apis. Then it feels like it would be easier to just write pl/sql batch jobs and schedule with concurrent manager in EBS (skip ODI completely). In that case, one could write to the concurrent manager log and the user could view the errors and correct.
    I can get a simple procedure to work in ODI where the source is the SQL, and the target is the pl/sql call to the stored proc in the database. It loops through every row in the sql source and calls the pl/sql code.
    But I can not see how to set which rows have failed and which table would log errors to begin with.
    Thank you,
    Erik

    Hi Erik,
    Please, take a look in these posts:
    http://odiexperts.com/?p=666
    http://odiexperts.com/?p=742
    They could help you in a way to solve your problem.
    I already used it to call Oracle EBS API's and worked pretty well.
    I believe that an IKM could be build to automate all the work but I never stopped to try...
    Does it help you?
    Cezar Santos
    http://odiexperts.com

  • "Best Practice" for a stored procedure that needs to access two schemas?

    Greetings all,
    When my company's application is deployed, two schema owners are typically created and all database objects divided between the two. I'll call them FIRST and SECOND.
    In a standard, vanilla implementation there is never any reason for the two to "talk to each other". No rights to objects in one schema are ever granted to the other.
    I am currently charged, however, with writing custom code to roll up data from one of the schemas and update tables in the other with the rollups. I have created a user whose job it is to run this process, and this user has the proper permissions to all necessary objects in both schemas. I'll call this user MRBATCH.
    Typically, any custom objects, whether they be additional staging tables, temp tables or stored procedures are saved in the FIRST schema. I tried to save this new stored procedure in the FIRST schema and compile it, but got "Insufficient priviliges" errors whenever the code in the stored procedure tried to access any tables in the SECOND schema. This surprised me a little bit because I had no plans to actually EXECUTE the stored procedure as FIRST, but I guess I can understand it from the point of view of, you ought be able to execute something you own.
    So which would be be "better" (assuming there's any difference): Grant FIRST all of the rights it needs in SECOND and save the stored procedure in FIRST, or could I just save the stored procedure in the MRBATCH schema? I'm not sure which would be "better practice".
    Is there a third option I'm overlooking perhaps?
    Thanks
    Joe

    In this case I would put it again into schema THIRD. This is a kind of API schema. There are procedures in it that allow some customized functionality. And since you grant only the right to execute those procedures (should be packages of cause) you won't get into any conflicts about allowing somebody too much.
    Note that this suggestion seems very similiar to putting the procedure directly to the executing user MRBATCH. It depends how this schemauser is used. I always prefer separating users from schemas.
    By definition the oracle object to represent a schema is identical to the oracle object representing a user (exception: externally defined users).
    my definition is:
    Schema => has objects (tables, packages) and uses tables space
    User => has priviledges (including create session and connect) and uses temp tablespace only. Might have synonyms and views.
    You can mix both, but sometimes it makes much sense to separate one from the other.
    Edited by: Sven W. on Aug 13, 2009 9:51 AM

  • Can I pass an array as an input parameter for a stored procedure on SQL Server 2000

    I am trying to pass an array to a stored procedure residing on my SQL Server 2000 database server. Is this even possible? If it is possible, what is the syntax for this?
    Any help would be greatly appreciated.
    Thanks

    I have passed arrays to and from a database using SQL and ActiveX, including to and from stored procedures, but I cannot recall the precise method used to do so. If memory serves, everything is in the form of a string. You need to do a lot of parsing and 'unparsing' to get this data into your stored procedure.
    You are left with a couple of options to get your data to the stored procedure. I recommend using SQL in LabVIEW wherever possible as it saves the amount of external code calls (and believe me, calling ActiveX procedures developed by someone else in Visual Basic is NOT much fun at all...). You can either send the array and other data to the stored procedure (you will find the syntax in the SQL references in LabVIEW help under SQL), or you can send
    the array to the database, and have the database then act upon the array.
    I strongly recommend making routines (subVIs) to handle these operations.
    Sorry I don't have the syntax, I don't have SQL installed on this machine. If you can't find the syntax in the help, please post here again.
    -Mike Du'Lyea

  • Model type  for DB stored procedures back end?

    I have to use a database via stored procedures (#>100) as a back end system in a web dynpro application.
    And I wonder which type of model is the most appropriate for that usage szenario.
    Of course, I have to create some kind of DAO to access the db and expose the stored procedures as methods of the DAO. But how to get the DAO functionality into the WD model?
    Do I have to go via web services, even if the DAO and the WD application run on the same instance? I think it is some kind of oversized. Would'nt the JavaBean model fit better? But how to get the DAO functionality into the JavaBean model?
    Thank you, best regards
    Christian Luehe

    Hi,
    For my knowledge create EJB and expose this as webservice and use webservice model in webdynpro.
    Regards, Anilkumar

  • CallableStatement - Calling a Stored Procedure having Null parameters

    Hi,
    Could anyone please let me know how I could call a PL/SQL procedure or a function from a JDBC
    method using CallableStatement? The procedure has 4 IN parameters - Param1,
    Param2, Param3, and Param4. Values are available for Param1 and Param2. Param3
    and Param4 have NULL values. Param3 has a SQL datatype of NUMBER and Param4 has
    a SQL datatype of Varchar2.
    We are using JDBC 2.0.
    Thanks.

    Problem solved :
    ArrayDescriptor + oracle.sql.ARRAY + String[] objects corresponding to the Oracle TABLE object.
    There are many examples on the web, but I just didn't manage to make them work before posting.

  • How to create AMDP's for sub stored procedures

    Hi,
    I am migrating Hana data base procedure to AMDP.
    I have HANA DP like below.
    procedure1.
       call procedure 2.
    endof procedure1.
    how to create AMDP in this case, i have created AMDP methods for both procedure1 and procedure2 but when i am calling AMDP of stored procedure2 in AMDP of stored procedure1  it's giving sqlscript syntax error since call method is an abap statement.
    can any one help me how to achieve this.
    Thanks
    Viswamurthy

    Dear Viswamurthy,
    You cannot use  CALL METHOD statements inside an AMDP Method as AMDP methods would not understand ABAP syntax.
    You need to use SQLScript CALL statements to call an AMDP method from an other AMDP method like below
    METHOD increase_price BY DATABASE PROCEDURE
                          FOR HDB LANGUAGE SQLSCRIPT
                          USING cl_demo_amdp_call_amdp=>increase_price_amdp.
      call "CL_DEMO_AMDP_CALL_AMDP=>INCREASE_PRICE_AMDP"(
        CLNT => :CLNT, INCPRICE => :INCPRICE );
    ENDMETHOD.
    You can find an example in the below link
    ABAP Keyword Documentation
    Hope this helps.
    Thanks
    Sundar

  • Creation of DB Adapter for calling stored procedure in MS SQL server 2008

    Hi,
    I am trying to create WSDL and XSD using oracle.tip.adapter.db.sp.artifacts.GenerateArtifacts command line tool to access a MS SQL Server 2008 store procedure and the utility throws the below error,
    C:\jdevstudio10134\integration\lib>java oracle.tip.adapter.db.sp.artifacts.GenerateArtifacts sp.properties
    Warning: Could not locate file pc.properties in classpath
    log4j:WARN No appenders could be found for logger (collaxa.cube.infrastructure).
    log4j:WARN Please initialize the log4j system properly.
    Database platform version is not supported.
    Attempt to use an unsupported database platform version: 10.
    Use a supported version of the database platform. Contact oracle support if error is not fixable.
    It seems this utilty is not supporting MS SQL server 2008 to create artifacts, can you please help me?
    Oracle SOA server: 10.1.3.4
    Driver used: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Thanks,
    Levey

    Hi Levey,
    The Oracle® Application Server Adapters for Files, FTP, Databases, and Enterprise Messaging User’s Guide 10g Release 3 (http://docs.oracle.com/cd/E11036_01/integrate.1013/b28994.pdf), only names Microsoft SQL Server 2000 and 2005. It provides some tips for integrating with MS SQL Server.
    The Oracle® Fusion Middleware User's Guide for Technology Adapters 11g Release 1 (http://docs.oracle.com/cd/E23943_01/integration.1111/e10231.pdf) does name Microsoft SQL Server 2008.
    Perhaps raise a SR to be sure.
    Kind regards, Ronald

  • Stored Procedure used as a data source for an Apex report

    Just wondering whether anyone has used a Stored Procedure as the data source for an Apex report. An option to select Stored Procedures(s) as the data source does not appear within the IDE (only displays Table, Views, Functions).
    Do you have to return the definition of the Stored Procedure via a function ... if so, how is this done ?
    Thank you.

    >
    Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "920338".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    Just wondering whether anyone has used a Stored Procedure as the data source for an Apex report. An option to select Stored Procedures(s) as the data source does not appear within the IDE (only displays Table, Views, Functions).
    Do you have to return the definition of the Stored Procedure via a function ... if so, how is this done ? When asking a question about "reports" it's firstly essential to differentiate between standard and interactive reports. Standard reports can be based on tables, views, SQL queries, or PL/SQL function blocks that return the text of a SQL query. Interactive reports can only be based on a SQL query.
    "Stored Procedures" are therefore not an option (unless you are using the term loosely to describe any PL/SQL program unit located in the database, thus including functions). What would a procedure used as the source of a report actually do? Hypothetically, by what mechanisms would the procedure (a) capture/select/generate data; and (b) make this data available for use in an APEX report? Why do you want to base a report on a procedure?

Maybe you are looking for

  • Import Manager   Delimiter Issue "|

    Hi,          We are facing a issue in during Import...We are loading Pipe Delimited file. Whenever we get "after |(Pipe) MDM is throwing an exception stating that 'Number of field values does not match the field columns'...Please let me know any body

  • How I can fix this error 1009 ???

    i'm living in syria always i got the error code 1009 so i can't download app from app store

  • Floorplan manager for Webdynpro

    Hello, I am working on Overview page floorplan OVP I wnat to know to the functionalities for the buttons SAVE, ADD(Insert) CANCEL (for the CANCEL button I want to cancel all the actions when user clicks on this button ). Regards, Jaffar Hasan

  • Requirement class- consumtion indicator and requirement reduction indicator

    hi in DEMAND MANAGEMENT WE CAN SET REQUIREMENT CLASS can any one elobrate whats the difference between the consumption indicator and requirement reduction indicator. in help i dint get any explanation regarding the indicators which we need to se at r

  • Weirdness happening on my Mac. Please help!

    Everyone, Please help. I've tried a lot of things this week to get this stupid weirdness out of my mac but it still won't go away. It's like someone's clicking on my mac or a keyboard key is stuck when i'm typing. I don't know what else to do. I unin