How to invoke a stored procedure on MS Sql Server with Java?

I started writing Enterprise Java Beans and created an ODBC dsn with MS Sql Server 2000 which I can access using jdbc:odbc:mySqlDSN. This all works fine using Java Sql Statements. What kind of Java/Java Sql statement can I use to invoke a stored procedure on the Sql Server? Is it possible to use ADO/ADO command objects with Java? Is it possible to import/implement Mdac2.6 ActiveX data objects libary in Java?
Thanks

Thanks all for your replies. I will search the api for callable statements. I am curious though, the reply that suggests using a prepared statement - can I put the name of a stored procedure in a prepared statment or is this just suggestions an action query like Insert Into, Update, Delete? Like with ADO you can say
cmdObject.CommandType = adStoredProcedure
cmdObject.CommandText = "NameOfStoredProc"
cmdObject.ExecuteNonQuery()
Once I am calling/importing/implementing the proper libraries/interfaces in Java, can a prepared statement reference a stored procedure as above?
Thanks

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

  • Writing a stored procedure to import SQL Server table data into a Oracle table

    Hello,
    As a new DBA I have been tasked with writing a stored procedure to import SQL Server table data into an Oracle table. I have been given many suggestions on how to do it from SQL Server but I I just need to write a stored procedure to run it from the Oracle side. Suggestions/guidance on where to start would be greatly appreciated! Thank you!
    I started to write it based on what I have but I know this is not correct :/
    # Here is the select statement for the data source in SQL Server...
    SELECT COMPANY
    ,CUSTOMER
    ,TRANS_TYPE
    ,INVOICE
    ,TRANS_DATE
    ,STATUS
    ,TRAN_AMT
    ,CREDIT_AMT
    ,APPLD_AMT
    ,ADJ_AMT
    ,TRANS_USER1
    ,PROCESS_LEVEL
    ,DESCRIPTION
    ,DUE_DATE
    ,OUR_DATE
    ,OUR_TIME
    ,PROCESS_FLAG
    ,ERROR_DESCRIPTION
      FROM data_source_table_name
    #It loads data into the table in Oracle....   
    Insert into oracle_destination_table_name (
    COMPANY,
    CUSTOMER,
    TRANS_TYPE,
    INVOICE,
    TRANS_DATE,
    STATUS,
    TRANS_AMT,
    CREDIT_AMT,
    APPLD_AMT,
    ADJ_AMT,
    TRANS_USER1,
    PROCESS_LEVEL,
    DESCRIPTION,
    DUE_DATE,
    OUR_DATE,
    OUR_TIME,
    PROCESS_FLAG,
    ERROR_DESCRIPTION)
    END;

    CREATE TABLE statements would have been better as MS-SQL and Oracle don't have the same data types.
    OUR_DATE, OUR_TIME will (most likely) be ONE column in Oracle.
    DATABASE LINK
    Personally, I'd just load the data over a database link:
    insert into oracle_destination_table_name ( <column list> )
    select ... <transform data here>
    from data_source_table@mssql_db_link
    As far as creating the database link from Oracle to MS-SQL ... that is for somebody else to answer.
    (most likely you'll need to use an ODBC driver)
    EXTERNAL TABLE
    If the data from MS-SQL is in a CSV file, just use and external table.
    same concept:
    insert into oracle_destination_table_name ( <column list> )
    select ... <transform data here>
    from data_source_external_table
    MK

  • How to invoke a stored procedures every hour? How to Cron ?

    Hi. I have written a stored procedure using PL/SQL and it needs to invoke every hour to reset certain value. My question is how to cron or to invoke the store procedure every hour? I'm using Oracle 9i database.
    Please advice if anyone of you had came acrossed this scenario.
    Thanks.

    As Kevin suggests, you can use cron to schedule the job, but you probably not be able to just use sqlplus on the command line. When a job is executed through cron, it nly gets the environment information that is in the global .login procedure, and nothing that is in your own .profile. In most cases, this means that that you need to call a shell script from cron, and set some environment variables. You can do this either by calling your .profile file, or by setting them explicitly.
    Another thing to consider in using cron is that the command line used to start SQL*Plus will be visible to anyone who can log on to the UNIX box. For this reason, we run all cron jobs that execute SQL using an externally identified Oracle user.
    Your minimal shell script should look something like:
    #!/usr/bin/ksh
    export ORACLE_HOME=/your/directory
    export ORACLE_SID=yoursid
    export PATH=$ORACLE_HOME/bin:$PATH
    sqlplus -s username/password @/path/sqlscript
    or alternatively
    #!/usr/bin/ksh
    . ~/.profile
    sqlplus -s / @/path/sqlscript
    Make sure that your sql script ends with an exit command to close SQL*Plus.
    John

  • How to invoke Oracle stored procedures in Web Intelligence Custom SQL ?

    Hi,
    Referring to some older posts, I see that there is a work around to invoke a stored procedure to return results for a Web Intelligence report. Its been posted for calling a MS SQL stored proc, whereas the mentioned method does not seem to work for an Oracle Stored Procedure.
    Steps I followed:
    a) This is the parameter I have added in the oracle.sbo file => <Parameter Name="Force SQLExecute">Procedures</Parameter>
    b) My stored procedure code is as follows:
    CREATE OR REPLACE PROCEDURE get_emp_details(var_first_name OUT VARCHAR) AS
    BEGIN
    SELECT first_name INTO var_first_name
    FROM EMP_DETAILS_VIEW
    WHERE EMPLOYEE_ID = 100;
    END;
    c) Custom SQL code I added in my Webi report:
    set nocount on;
    /* SELECT
    EMP_DETAILS_VIEW.FIRST_NAME
    FROM
    EMP_DETAILS_VIEW
    exec get_emp_details;
    On trying to validate the SQL it gives me the following error message: "The SQL query has 0 instead of 1 columns.(WIS 10810)"
    Has anyone been able to successfully call an Oracle Stored procedure using the above method ?
    Version of BO: XI R3 SP2
    Oracle version: 11gR2
    PS: I am aware that web intelligence since XI R3.1 does allow use of a dedicated Stored Procedure Universe. I would want to know if it could
    be made to run in a normal Universe(not a stored procedure Universe)
    Thanks for your time and inputs.
    Regards,
    Jez

    EXECUTE is a SQL Plus command. You can directly call SP in PL/SQL
    DECLARE
        modif number;
    BEGIN
    select data_length into modif from user_tab_columns where table_name='CONTROL' and column_name='POSITION';
    IF modif < 10 THEN
        droptable('CONTROL');
        execute immediate('CRETAE TABLE CONTROL ....';
    ...

  • How to invoke a stored procedure from SubmitEditForm.jsp

    Instead of directly inserting or updating
    the data I would like to invoked
    the stored procedure.
    Has anybody done this?

              Sam,
              BEA provides examples that are shipped with the product under
              <beahome>\weblogic700\samples\server\src\examples\
              Look at the jsp directory for JSP examples that access a database and look at
              say the jdbc\oracle\storedprocs.java for an example of java code calling out to
              a stored procedure - - by combining one of the jsp database examples with this
              stored procedure example you should be 'good to go'
              Chuck Nelson
              DRE
              BEA Technical Support
              

  • How do write a stored Procedure in PL/SQL

    Hi,
    I am new to this forum. I am creating a webpage using Gridview in Visual Studio 2005.
    How to write a Stored procedure in Oracle using PL/SQL?
    I want to write a SP for the following query :
    "Select S_No, Task_ID,Last_Act_Dt,Last_Act_Tm,Status from E002 Order by S_No"
    Please help.

    In Oracle, you normally wouldn't create a stored procedure that just does a query. Depending on what you're attempting to do on the client side, and the client libraries involved, you may be able to write a stored procedure that returns a REF CURSOR and call that. This will put some limitations on what the client can do with the results, for example. The data would be read-only and scrolling back and forth in the result set would potentially rather slow and rather expensive in terms of client memory. That makes this generally a somewhat unattractive option.
    You could create a view in Oracle and just query the view in your application code. If you needed to change the query, you could then just change the view.
    Justin

  • Calling Managed CLR Stored Procedure from C++ SQL Server 2008 fails with Msg 2809

    I am trying to call a stored procedure from C++ (VS 2010).
    Here is what the stored procedure looks like:
    public class Validate
    [Microsoft.SqlServer.Server.SqlProcedure(Name = "ClientTest")]
    public static void ClientTest(out String res )
    { res = "50";}
    To create a stored procedure I deploy at first the assembly
    USE [test]
    GO
    CREATE ASSEMBLY ClientTestAssembly
    AUTHORIZATION testLogin
    FROM 'C:\Users\test\Documents\Visual Studio 2010\Projects\TestCreationAssemblyCSharp\TestCreationAssemblyCSharp\bin\x64\Debug\TestCreationAssemblyCSharp.dll'
    and call 
    USE test
    GO
    CREATE PROCEDURE ClientTest (@res NVARCHAR(40) OUTPUT)
    AS
    EXTERNAL NAME ClientTestAssembly.Validate.ClientTest
    I can call my procedure direct in SQL Server Management Studio without any errors
    declare @res nvarchar(10)
    execute ClientTest @res OUTPUT
    print @res
    But when I try to call this procedure from C++ using CALL syntax
    SQLBindParameter(sqlstatementhandle, 1, SQL_PARAM_OUTPUT, SQL_C_CHAR,
    SQL_VARCHAR , 40, 0, version, sizeof(version) ,
    &pcbValue);
    res = SQLExecDirect(sqlstatementhandle, (SQLCHAR*)("{CALL ClientTest(?) }"), SQL_NTS);
    I get the Error 2809 with SQLSTATE 42000 and with statement 
    The request for 'ClientTest'
    (procedure) failed because 'ClientTest' is a procedure object.
    However, if I wrap my CLR stored procedure into a T-SQL stored procedure, like
    CREATE PROCEDURE myProc (@res NVARCHAR(40) OUTPUT)
    AS
    EXEC ClientTest @res OUTPUT
    and call then myProc instead of ClientTest
    res = SQLExecDirect(sqlstatementhandle, (SQLCHAR*)("{CALL myProc(?) }"), SQL_NTS);
    everithing works fine and I get 50 as result.
    I have no ideas what is the reason for that behavior.
    Thanks very much for any suggestion. 
    Christina

    I'm not an ODBC expert, but you might try following the sample here:
    Process Return Codes and Output Parameters (ODBC)
    To see if it also behaves differently for your CLR proc.
    David
    David http://blogs.msdn.com/b/dbrowne/

  • How to invoke a stored procedure in database adapter

    Hi All,
    i have created a database adapter which contains a stored procedure, the procedure is merge process,which bring data from another database,
    i have made sure that checking for new records and updating any changes from the source database everything has been taken care in the procedure.
    my question is how to invoke this process, what all process activities need to be associated with the database adapter, to invoke it
    assuming i want to run it every 5 hours,
    any reply would be of great help.
    Regards
    Ananth

    Hi,
    V thanks for you reply, i am v much new to this bpel environment, i tried using invoke but got errors like
    Error(61):
    [Error ORABPEL-10107]: Invalid initial activities
    [Description]: in line 61 of "C:\jdevstudio10134\jdev\mywork\Incremental_refresh\data_incr_refresh\bpel\data_incr_refresh.bpel", Initial activity is invalid. An initial activity must be of a receive or pick activity..
    [Potential fix]: Please re-arrange the BPEL process definition to make sure its initial activity is of a receive or pick activity. (e.g. by adding new receive activity or removing invalid initial activities..
    Error:
    [Error ORABPEL-10063]: missing initial receive activity
    [Description]: in "C:\jdevstudio10134\jdev\mywork\Incremental_refresh\data_incr_refresh\bpel\data_incr_refresh.bpel", there is no receive activity that starts the process.
    [Potential fix]: make sure one of "pick" and "receive" activities have attribute      "createInstance" set to be "yes".
    later i used the service pick, so from pick i am heading to ivoke and later to finally database adapter, but still getting below error
    Error(59):
    [Error ORABPEL-10900]: xml parser error
    [Description]: in line 59 of "file:/C:/jdevstudio10134/jdev/mywork/Incremental_refresh/data_incr_refresh/bpel/data_incr_refresh.bpel", XML parsing failed because file:/C:/jdevstudio10134/jdev/mywork/Incremental_refresh/data_incr_refresh/bpel/data_incr_refresh.bpel<Line 59, Column 19>: XML-24536: (Error) Missing Attribute 'partnerLink'.
    [Potential fix]: Fix the invalid XML.
    Error(59):
    [Error ORABPEL-10900]: xml parser error
    [Description]: in line 59 of "file:/C:/jdevstudio10134/jdev/mywork/Incremental_refresh/data_incr_refresh/bpel/data_incr_refresh.bpel", XML parsing failed because file:/C:/jdevstudio10134/jdev/mywork/Incremental_refresh/data_incr_refresh/bpel/data_incr_refresh.bpel<Line 59, Column 19>: XML-24536: (Error) Missing Attribute 'portType'.
    [Potential fix]: Fix the invalid XML.
    Error(59):
    [Error ORABPEL-10900]: xml parser error
    [Description]: in line 59 of "file:/C:/jdevstudio10134/jdev/mywork/Incremental_refresh/data_incr_refresh/bpel/data_incr_refresh.bpel", XML parsing failed because file:/C:/jdevstudio10134/jdev/mywork/Incremental_refresh/data_incr_refresh/bpel/data_incr_refresh.bpel<Line 59, Column 19>: XML-24536: (Error) Missing Attribute 'operation'.
    [Potential fix]: Fix the invalid XML.

  • How to invoke a stored procedure by WSIF?

    If it can, how to do? what the WSDL looks like?
    Can anybody give me an example?
    Thanks.

    Thanks all for your replies. I will search the api for callable statements. I am curious though, the reply that suggests using a prepared statement - can I put the name of a stored procedure in a prepared statment or is this just suggestions an action query like Insert Into, Update, Delete? Like with ADO you can say
    cmdObject.CommandType = adStoredProcedure
    cmdObject.CommandText = "NameOfStoredProc"
    cmdObject.ExecuteNonQuery()
    Once I am calling/importing/implementing the proper libraries/interfaces in Java, can a prepared statement reference a stored procedure as above?
    Thanks

  • How to invoke DB stored procedures from EJB3.0

    In our project we are using EJB3.0.
    I got one situation, where i need to call a db stored procedure through my code. But i couldn't find any possibilities.
    Can any body help me in this regard
    Thanks in advance
    Kiran

    Hi,
    As per ejb3.0 spec is conserned it doesnt specify anything with regard to stored procedures as of now, it means ejb3.0 cannot handle stored procedures as of now, of course it still depends on vendor implemenation u can check out for any possibilities wether vendor provides support for it or not, as for as i am conserned they dont as of now.
    Possible Alternative:
    This can be achived only through BMT using 2 transactions.
    Open a seperate JDBC managed Transaction(by setting AutoCommit to false) execute the stored procedures from here, u can commit or roll back from there on.
    Thanks and Regards
    Srikanth S

  • How can I Use a Stored Procedure from Microsoft SQL Server?

    Hi All,
    Would like to use stored procedure as my data service in Visual Composer.
    Our version is VC7.0 SP20.
    Is stored procedure feasible? What is the system that i need to create  in Enterprise Portal? Currently i have BI JDBC System which only allows me to search for tables from SQL Server.
    Much appreciate your help.
    Thanks & Regards,
    Sarah

    Hi Skif,
    Referring to my post: JDBC System Connection VS BI JDBC System Connection
    I do not even able to view list of stored procedure. I need help too..maybe you can show me how do you set the connection? What are the mandatory connection properties? I have filled up:
    - Connection URL
    - Driver class name
    - User Administration: User, Admin (I did user mapping too)
    The error message that i got is:
    com.sap.guimachine.portalconnector.commandhandler.CommandException: Failed to connect to backend system. Check your system definition and user privileges.#
    I had assigned full control to the DB user, and map my portal user to that DB user.
    Many Thanks,
    Sarah

  • DB Adapter calling stored procedure in MS SQL Server.

    Hi
    i am calling a stored procedure in a MS SQL Server.
    I configured a Datasource for MS SQL Server driver as Oracle's MS SQL Server Driver(Type 4) Versions: 7.0 and later and provide all db details of sql server. I tested the data source and was getting success message. My BPEL code is just talking with input parameter and then calling the stored procedure in sql server. I was able to compile the code in jdeveloper and deploy to weblogic. But when i am testing the code. i am getting an error.
    <env:Fault>
    <faultcode>env:Server</faultcode>
    <faultstring>Exception occured when binding was invoked.
    Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'IDMService' failed due to: JCA Binding Component connection issue.
    JCA Binding Component is unable to create an outbound JCA (CCI) connection.
    Test:IDMService [ IDMService_ptt::IDMService(InputParameters,OutputParameters) ] : The JCA Binding Component was unable to establish an outbound JCA CCI connection due to the following issue: javax.resource.spi.IllegalStateException: [Connector:199176]Unable to execute allocateConnection(...) on ConnectionManager. A stale Connection Factory or Connection Handle may be used. The connection pool associated with it has already been destroyed. Try to re-lookup Connection Factory eis/sql/idm from JNDI and get a new Connection Handle.
    Please make sure that the JCA connection factory and any dependent connection factories have been configured with a sufficient limit for max connections. Please also make sure that the physical connection to the backend EIS is available and the backend itself is accepting connections.
    The invoked JCA adapter raised a resource exception.
    Please examine the above error message carefully to determine a resolution.</faultstring>
    <faultactor/>
    <detail>
    <exception>[Connector:199176]Unable to execute allocateConnection(...) on ConnectionManager. A stale Connection Factory or Connection Handle may be used. The connection pool associated with it has already been destroyed. Try to re-lookup Connection Factory eis/sql/idm from JNDI and get a new Connection Handle.</exception>
    </detail>
    </env:Fault>
    What is the problem with connection . How cna i rectify it.
    Thanks,
    Venu Raja

    followed the steps mentioned in meatalnk..
         JCA-12563 - Unable to Establish an Outbound JCA CCI Connection [ID 1235943.1]
    Metalink ID - 1235943.1

  • Where are User Defined Functions and Stored Procedures kept in SQL Server?

    Hi,
    I have a growing list of Stored Procedures and User-Defined Functions in SQL Server, and would like to be able to list all my user SP and UDF easily.
    Is it possible to write a query to list all SP and UDF?
    I saw the following specimen code in an SQL book, but am not sure this is what I need because I could not make it work.
    SELECT *
        FROM INFORMATION_SCHEMA.ROUTINES
    WHERE SPECIFIC_SCHEMA = N'CustomerDetails'
        AND SPECIFIC_NAME = N'apf_CusBalances'
    I tried:
    SELECT *
        FROM INFORMATION_SCHEMA.ROUTINES
    but it does not work.
    Suppose all my SP are named following this pattern:
        dbo.usp_Storeproc1
    How would I modify the above code? or is there a better code?
    Thanks
    Leon Lai

    Hi ,
    try this to get list of all stored procedures:
    SELECT *
    FROM sys.procedures where name like 'dbo.usp%'
    Thanks,
    Neetu

  • Translate Stored Procedure from MS SQL Server to ORACLE 9i

    Hi...
    I work usually with MS SQL Server, and now I need to migrate an application from MS SQL Server to ORACLE 9i. I think to preserve most of User Interface made actually in MS Visual Basic .NET 2003 and change or "translate" all the MS SQL Server stored procedures to ORACLE 9i(most of business logic was code in Stored Procedures). So I need an advise of how to do that, if there are a tool for migration (tables, PK, FK, Rules, Defaults...etc) and, if possible, a procedure or tips for translate the stored procedures.
    Thanks in advance....
    Eusebio M

    Here's some links:
    Oracle Migration Workbench:
    http://www.oracle.com/technology/tech/migration/workbench/index.html
    Forums for Migration:
    http://forums.oracle.com/forums/forum.jspa?forumID=183
    Database and Application Migrations
    Good luck!
    Christian

Maybe you are looking for

  • Calendar in month view has no data until the page is swiped

    For the past couple of months, when I first open Calendar and it is in month view from a previous use, none of my entries show up. The phases of the moon and birthdays are all that will show. This only affects the month view. If I then swipe to anoth

  • Can we use BLOB fields (that store images) in Crystal Report ?

    I'm developing with ASP.NET, VS.NET 2003. Using Crystal Report for VS.NET DataBase: Oracle 10g I store a BLOB field in a table. This field store images, like jpg files. The Stored Procedure that I use to fill the report is: OPEN MyCursor FOR SELECT M

  • JMS adapter error in MQSeries connection

    Dear All, i am getting the below error in Communicatin Channel Monitoring for my sender JMS adapter: Error during channel initialization; exception trace: javax.jms.JMSException: MQJMS2005: failed to create MQQueueManager for '<IP_ADRESS>:<MQ_QUEUE_M

  • Getting PDF files doesn't work on Windows 7?

    Hi,    I had a working installation of Adobe Output Central v5.5 on a Windows 2000 machine. I then tried to move it to Windows 7 because we want to change the hardare. I set up all programs to run as Windows 2000 under windows 7 (this is something yo

  • Custom table column based on value scale

    I want to custom table column based on the vaules. I understood I need to to /1000000 in the column definition and custom ###,###,###M. But sometimes it can be Kilos and sometimes Billions. I don't want to display 0.02M or 200000M. How can I define c