Prevent Duplicates from Inserting from File in Stored Procedure

CREATE TABLE dbo.Logins
[ID] numeric(10, 0) NOT NULL Primary Key,
[Dr_FName] varchar(50) NOT NULL,
[Dr_LName] varchar(50) NOT NULL,
[Login] varchar(50) NOT NULL
GO
CREATE TABLE [dbo].[CRIS_USER] (
[id] numeric(10, 0) NOT NULL Primary Key,
[login_id] varchar(20) NOT NULL
GO
CREATE TABLE [dbo].[CRIS_SYSTEM_USER] (
[id] numeric(10, 0) NOT NULL Primary Key,
[cris_user_id] numeric(10, 0) NOT NULL,
INSERT INTO Logins
(ID, Dr_FName, Dr_LName,Login)
VALUES(1,'Lisa','Mars','lmars')
INSERT INTO Logins
(ID, Dr_FName, Dr_LName,Login)
VALUES(2,'Becky','Saturn','bsaturn')
INSERT INTO Logins
(ID, Dr_FName, Dr_LName,Login)
VALUES(3,'Mary','Venus','mvenus')
INSERT INTO CRIS_USER
(ID,login_id)
VALUES(10, 'lmars')
INSERT INTO CRIS_USER
(ID,login_id)
VALUES(20, 'bsaturn')
INSERT INTO CRIS_USER
(ID,login_id)
VALUES(30, 'mvenus')
INSERT INTO CRIS_SYSTEM_USER
(ID,cris_user_id)
VALUES(110, 10)
INSERT INTO CRIS_SYSTEM_USER
(ID,cris_user_id)
VALUES(120,20)
INSERT INTO CRIS_SYSTEM_USER
(ID,cris_user_id)
VALUES(130, 30)
I'm aware that "ID" is a bad column name and that it should not be numeric. The ID columns are incremented by a program. They are not auto incremented. I didn't design it.
I have a stored procedure that does a bulk insert from a tab delimited file into the three tables:
CREATE PROCEDURE [dbo].[InsertUserText]
WITH EXEC AS CALLER
AS
IF OBJECT_ID('TEMPDB..#LoginTemp') IS NULL
BEGIN
CREATE TABLE #LoginTemp(Login varchar(50),Dr_FName varchar(50),Dr_LName varchar(50))
BULK INSERT #LoginTemp
FROM 'C:\loginstest\InsertUserText.txt'
WITH (ROWTERMINATOR ='\n'
-- New Line Feed (\n) automatically adds Carrige Return (\r)
,FIELDTERMINATOR = '\t'
--delimiter
,FIRSTROW=4)
PRINT 'File data copied to Temp table'
END
DECLARE @maxid NUMERIC(10,0)
DECLARE @maxid2 NUMERIC(10,0)
DECLARE @maxid3 NUMERIC(10,0)
BEGIN TRANSACTION
SELECT @maxid = coalesce(MAX(ID), 0)
FROM dbo.LOGINS WITH (UPDLOCK)
INSERT INTO dbo.LOGINS(ID,Dr_FName,Dr_LName,Login)
SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid,
Dr_FName,Dr_LName,Login
FROM #LoginTemp
WHERE #LoginTemp.Dr_FName is not Null;
SELECT @maxid3 = coalesce(MAX(id), 0)
FROM dbo.CRIS_USER WITH (UPDLOCK)
INSERT INTO dbo.CRIS_USER(id,login_id)
SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid3,
Login
FROM #LoginTemp
WHERE #LoginTemp.Dr_FName is not Null;
SELECT @maxid2 = coalesce(MAX(id), 0)
FROM dbo.CRIS_SYSTEM_USER WITH (UPDLOCK)
INSERT INTO dbo.CRIS_SYSTEM_USER(id,cris_user_id)
SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid2,
+ row_number() OVER(ORDER BY (SELECT NULL)) + @maxid3
FROM #LoginTemp
WHERE #LoginTemp.Dr_FName is not Null;
PRINT 'Copied from Temp table to CRIS_USER'
COMMIT TRANSACTION
GO
What suggestions do you have to prevent a duplicate Logins.Login? None of the inserts for all three tables should occur if a login already exists in the Logins table. There should be a message to indicate which Login failed. I haven't yet decided if I want
all of the logins in the text file to fail if there is a duplicate, or just the one with the duplicate. I'm open to suggestions on that. So far, the duplicates only occur when someone forgets to update the tabbed delimited file and accidently runs the procedure
on an old one. I'm sure I can come up with an if statement that will accomplish this. I could maybe use WHERE EXISTS or WHERE NOT EXISTS. But I know I can get a good solution here.
I'm also aware that duplicates could be prevented in the table design. Again, I didn't design it.
I have a tab delimited file created but don't see a way to attach it.
Thanks for any help.

Thanks to all three that replied. I meant to mark the question as answered sooner. I've tried all the suggestions on a test system. All will work with maybe some slight variations. Below was my temporary quick fix. I'm working on switching to a permanent
solution based on the replies.
This is not the real solution and is not the answer to my question. It's just temporary.
IF OBJECT_ID('TEMPDB..#LoginTemp') IS NULL
BEGIN
CREATE TABLE #LoginTemp(Login varchar(50),Dr_FName varchar(50),Dr_LName varchar(50))
BULK INSERT #LoginTemp
FROM 'C:\loginstest\InsertUserText.txt'
WITH (ROWTERMINATOR ='\n'
Return (\r)
,FIELDTERMINATOR = '\t'
,FIRSTROW=4)
PRINT 'File data copied to Temp table'
END
DECLARE @maxid NUMERIC(10,0)
DECLARE @maxid2 NUMERIC(10,0)
DECLARE @maxid3 NUMERIC(10,0)
IF EXISTS(SELECT 'True' FROM Logins L INNER JOIN #LoginTemp LT on L.Login = LT.Login
BEGIN
SELECT 'Duplicate row!'
END
ELSE
BEGIN
BEGIN TRANSACTION
SELECT @maxid = coalesce(MAX(ID), 0)
FROM dbo.LOGINS WITH (UPDLOCK)
INSERT INTO dbo.LOGINS(ID,Dr_FName,Dr_LName,Login)
SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid,
Dr_FName,Dr_LName,Login
FROM #LoginTemp
WHERE #LoginTemp.Dr_FName is not Null;
SELECT @maxid3 = coalesce(MAX(id), 0)
FROM dbo.CRIS_USER WITH (UPDLOCK)
INSERT INTO dbo.CRIS_USER(id,login_id)
SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid3,
Login
FROM #LoginTemp
WHERE #LoginTemp.Dr_FName is not Null;
SELECT @maxid2 = coalesce(MAX(id), 0)
FROM dbo.CRIS_SYSTEM_USER WITH (UPDLOCK)
INSERT INTO dbo.CRIS_SYSTEM_USER(id,cris_user_id)
SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid2,
+ row_number() OVER(ORDER BY (SELECT NULL)) + @maxid3
FROM #LoginTemp
WHERE #LoginTemp.Dr_FName is not Null;
COMMIT TRANSACTION
END
GO

Similar Messages

  • Transactional file output from a Java Stored Procedure invoked by trigger.

    I need to write information to a file from a Java Stored
    Procedure which is called from an insert trigger. This works OK
    except for the condition when a rollback is performed - the file
    is updated anyway.
    I need the Java Stored Procedure file output to be part of the
    transaction - performed on commit and skipped on rollback. Is
    there any way the Java Stored Procedure can be aware of the
    state of the transaction?

    i am Still facing the following problem:
    if i pass a parameter like :
    rm -f /test/menu.ksh
    then the required output is that the menu.ksh file gets deleted.
    but when i pass this command:
    ./test/menu.ksh
    It is supposed to execute the specified script but it does not.
    I have tried multiple things like giving chmod 777 rights to the following file and changing the command to /test/menu.ksh but nothing happens
    Can you kindly tell me what can the problem be. Is there any execution rights issue: i am executing these scripts from pl sql developer.
    You can find both the procedure and java method which is being called below
    ==========================================================================================
    create or replace procedure TEST_DISPLAY(filename in varchar2, result out varchar2, error out varchar2) is
    command varchar2(100);
    vRetChar varchar2(100);
    begin
    command := filename ;
    prc_host(command, vRetChar);
    result := vRetChar;
    dbms_output.put_line(result);
    Exception
    when No_Data_Found Then
    error := 'Command is not Found';
    dbms_output.put_line('Failure');
    return;
    end TEST_DISPLAY;
    ======================================================================
    create or replace and compile java source named host as
    import java.io.*;
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.IOException;
    import java.lang.InterruptedException;
    public class Host {
    public static void executeCommand(String command,String[] outString) {
    String RetVal;
    try {
    String[] finalCommand;
    final Process pr = Runtime.getRuntime().exec(command);
    // Capture output from STDERR...
    }

  • I would like to prevent any user including admins from modifying a stored procedure

    I would like to prevent any user including admins (apart from myself) from modifying a stored procedure.
    I cant use encryption because i need people to be able to read the code, I cant use trigger because we arent able to add triggers to system tables. 
    Any ideas?

    You cannot prevent from the logins who are members of sysadmin role to modify stored procedures.
    If you DENY ALTER SCHEMA then the user won't be able to issue any DDL changes (CREATE, ALTER, DROP) that affect objects in that schema
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Preventing duplicate rows insertion

    suppose i have a table with 2 columns
    no constraints are there
    then how i will prevent duplicate rows insertion using triggers.

    but i tried to solve the poster's requirement.yes, but the trigger does not solve it.
    The example you posted above, try this:
    do the first insert in your first sql*plus session, and then without committing, open another sql*plus session and do the second insert.
    Do you see an error?
    SQL> create table is_dup(x number, y varchar2(10));
    Table created.
    SQL> CREATE OR REPLACE TRIGGER chk
      2      BEFORE INSERT ON is_dup
      3      FOR EACH ROW
      4  BEGIN
      5      FOR i IN (SELECT * FROM is_dup)
      6      LOOP
      7          IF (:NEW.x = i.x) AND
      8             (:NEW.y = i.y)
      9          THEN
    10              raise_application_error(-20005, 'Record already exist...');
    11          END IF;
    12      END LOOP;
    13  END;
    14  /
    Trigger created.
    SQL> insert into is_dup values(123,'MYNAME');
    1 row created.
    SQL>
    SQL> $sqlplus /
    SQL*Plus: Release 10.2.0.1.0 - Production on Sun Apr 23 10:17:07 2006
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> insert into is_dup values(123,'MYNAME');
    1 row created.
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select * from is_dup ;
             X Y
           123 MYNAME
           123 MYNAME
    SQL> commit ;
    Commit complete.
    SQL> select * from is_dup ;
             X Y
           123 MYNAME
           123 MYNAME
    SQL>

  • BO v5.1 - creating a report from an oracle stored procedure

    Post Author: newrochelle
    CA Forum: Publishing
    hi to all,
    im using BO 5.1 and i need to create a document from an oracle stored procedure that have only one IN parameter and ten OUT parameters.
    Creating the new report I selected the database connection then I choose the stored procedure name from the list, I inserted the value for the IN parameter and finally I click on Run button.
    I got the following error message:
    ORA-06550: line 1, column 38: :PLS-00103: Encountered the symbol
    "," when expecting one of the following: : : ( - + case mod
    new not null others <an identifier> : <a double-quoted
    delimited-identifier> <a bind variable> avg : count current
    exists max min prior sql stddev sum variance : execute forall
    merge time timestamp interval date : <a string literal with
    character set specification> : <a number> <a single-quoted SQL
    string> pipe : <an alternatively-quoted string literal with
    character set specification> : <an alternatively-q :-6550
    it seems to be caused by the OUT parameters!
    i leaved them without any value.
    it's the first time that I used a stored procedure to create a BO report, but I think the OUT parameters are needed to do that, otherwise what data will be presented in the report???
    can you help me?
    please answear me ASAP.
    Thank's in advance
    Regards
    Andrea

    Post Author: synapsevampire
    CA Forum: Publishing
    Try posting in a BO forum, this is Crystal Reports.
    -k

  • T-sql 2008 r2 place results from calling a stored procedure with parameters into a temp table

    I would like to know if the following sql can be used to obtain specific columns from calling a stored procedure with parameters:
    /* Create TempTable */
    CREATE TABLE #tempTable
    (MyDate SMALLDATETIME,
    IntValue INT)
    GO
    /* Run SP and Insert Value in TempTable */
    INSERT INTO #tempTable
    (MyDate,
    IntValue)
    EXEC TestSP @parm1, @parm2
    If the above does not work or there is a better way to accomplish this goal, please let me know how to change the sql?

    declare @result varchar(100), @dSQL nvarchar(MAX)
    set @dSQL = 'exec @res = TestSP '''+@parm1+''','' '''+@parm2+' '' '
    print @dSQL
      EXECUTE sp_executesql @dSQL, N'@res varchar(100) OUTPUT', @res = @result OUTPUT
    select @result
    A complicated way of saying
    EXEC @ret = TestSP @parm1, @parm2
    SELECT @ret
    And not only compliacated, it introduces a window for SQL injection.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Retrieving a UDT object from a Java Stored Procedure

    I am really having trouble returning a UDT object (AttributeUDT) from a Java stored procedure. I am using Oracle 8.1.6 and JDeveloper 3.2.2. I have successfully used JPublisher to create the Java source code files for my UDT, now I would like to use that in coordination with my Java stored procedure. I've loaded the Java stored procedure into the database using the Deployment option in JDeveloper. However, when it loads the procedure, it translates the 3rd parameter to an OBJECT type, thus making the stored procedure invalid. I can use SQL Navigator to correct the package by changing the OBJECT reference to AttributeUDT (my UDT data type). Unfortunately, my Java stored procedure still does not work. Any help would be greatly appreciated! Thanks in advance for your time!
    In the example below, could anyone please tell me:
    1. How do I register the OUT variable for the UDT?
    2. Is it correct to use the casted call to getObject to retrieve my UDT object?
    3. Is it valid to use the UDT data type in the java stored procedure method signature?
    The call to the Java stored procedure:
    OracleCallableStatement cs3 = (OracleCallableStatement)conn.prepareCall( "{ call sandbox.getQualifiersV3( ?, ?, ?) }");
    cs3.registerOutParameter( 1, Types.VARCHAR);
    cs3.registerOutParameter( 2, Types.VARCHAR);
    cs3.registerOutParameter( 3, ???????);
    cs3.execute();
    System.out.println( "ID: " + cs3.getString( 1));
    System.out.println( "Prompt: " + cs3.getString( 2));
    AttributeUDT attributes = (AttributeUDT)cs3.getObject( 3);
    System.out.println( "Table id: " + attributes.getLogicalTableId());
    System.out.println( "Element id: " + attributes.getElementId());
    cs3.close();
    ===========================================
    The Java stored procedure:
    public static void getQualifiersV3( String ids[], String prompts[],
    AttributeUDT attributes[]) throws SQLException {
    OracleConnection conn = (OracleConnection)new OracleDriver().defaultConnection();
    Statement stmt = conn.createStatement();
    OracleResultSet rs = (OracleResultSet)stmt.executeQuery(
    "SELECT * "
    + "FROM VPS_ABOK_QUALIFIERS "
    + "WHERE qualifier_id = 2001");
    rs.next();
    ids[0] = rs.getString( 1);
    prompts[0] = rs.getString( 2);
    attributes[0] = (AttributeUDT)rs.getCustomDatum( 3, AttributeUDT.getFactory());
    rs.close();
    stmt.close();
    null

    Sounds like your C2 REF TYP1 attribute may be null. Unfortunately you neglected to say where in your code the NullPointerException occurs.

  • Invoking "java myClass" using Runtime.Exec from a Java Stored Procedure

    Hi All,
    This is regarding the use of Runtime.getRunTime().exec, from a java programme (a Java Stored Procedure), to invoke another Java Class in command prompt.
    I have read many threads here where people have been successuful in invoking OS calls, like any .exe file or batch file etc, from withing Java using the Runtime object.
    Even i have tried a sample java programme from where i can invoke notepad.exe.
    But i want to invoke another command prompt and run a java class, basically in this format:
    {"cmd.exe","java myClass"}.
    When i run my java programme (in command prompt), it doesnt invoke another command prompt...it just stays hanging.
    When i run the java programme from my IDE, VisualCafe, it does open up a command prompt, but doesnt get the second command "java myCLass".
    Infact on the title of the command prompt (the blue frame), shows the path of the java.exe of the Visual Cafe.
    and anyway, it doesnt run my java class, that i have specified inside the programme.
    Even if i try to run a JAR file, it still doesnt do anything.
    (the JAR file other wise runs fine when i manually invoke it from the command prompt).
    Well, my question is, actually i want to do this from a Java Stored Procedure inside oracle 8.1.7.
    My feeling is, since the Java Stored Procedure wont be running from the command prompt (i will be actually invoking it through a Oracle trigger), it may be able to invoke the command prompt and run the java class i want. and that java class has to run with the SUn's Java, not Oracle JAva.
    Does any one have any idea about it?
    Has anyone ever invoked a java class or JAR file in command prompt from another Java Programme?
    YOur help will be highly appreciated.
    (P:S- Right now, my database is being upgraded, so i havent actually been able to create a Java Stored procedure and test it. But i have tested from a normal java programme running in command prompt and also from Visual Cafe).
    Thanks in advance.
    -- Subhasree.

    Hello Hari,
    Thanks for your quick reply.
    Can you please elaborate a little more on exactly how you did? may be just copy an dpaste taht part of teh code here?
    Thanks a lot in advance.
    --Subhasree                                                                                                                                                                                                                                                                                                                                                                                                           

  • Calling JPA from a Java Stored Procedure

    Is it possible to call JPA from a java stored procedure? If so, does anyone have example? How do you setup the persistence.xml?
    How does the peformance compare with straight JDBC in a java stored procedure?
    Thanks for any help!
    Johnny

    Hi Johnny:
    Basically you can run any JDK 1.5 framework inside your Oracle 11g JVM, I have experience integrating Lucene IR library as a new [Domain Index for Oracle 11g/10g|http://docs.google.com/View?id=ddgw7sjp_54fgj9kg] .
    I am not familiar with JPA internals but my advice is howto handle the connection inside the OJVM and the configuration files.
    Some time ago I took a look to SpringFramework integration and I found that writing a new ApplicationContext class which handles the loading of beans.xml from XMLDB repository instead a file should be enough to work.
    Another important point is the life cycle of the [Oracle internal JVM|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABHGJFI]. Unlike an standard JVM the OJVM is created once you first connect from the middle tier at OCI level and remains in execution during the connection pool existence.
    I mean, if you connect using a JDBC pool the JVM will remains running across multiple soft open/close connections of your middle tier application. This is good because you can read your persistence.xml file using a Singleton class and this expensive operation will be re-used by multiple open/close operation done from the middle tier.
    I suggest you do a simple Proof of Concept with a Hello World application and check if it works.
    Remember that any security issues will be notified to the .trc files, security issues are related to the strong security layer configured by default inside the OJVM, for example you can not read any files from the OS file system without an specific grant, you need another grant to access to the class loader and so on, but you can simply grant this specific needs to a database role and then grant this role to the user which connect to the OJVM.
    Another important point is related to the [End-of-Call Optimization|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABIFAAI] this can be useful if you want to perform some clean up in your Singleton class at the level of per-statement execution.
    Best regards, Marcelo

  • Creating a table/view or temporary table from within a stored procedure

    Hi Gurus,
    Can someone tell me if it is possible to create a table (or view) from within a stored procedure.
    PROBLEM:
    In fact I need to create a report at back end (without using oracle developer forms or reports). This report requires creating several tables to hold temporary report data. If I create a sql*plus script for this, i works fine, because it can run DDL and other sql or pl/sql statements sequencialy. But this sql*plus script cannot be called from application. So, application needs an stored procedure to do this task and then application call that procedure. But within stored procedure, i am unable to create table (or run any ddl statement). Can somebody help me in this?
    Thanks in Advance.

    Denis,
    The problem with Nicholas' suggestion isrelated to the fact that now you have two components
    (a table and a stored procedure)
    I don't see any problem to have "two
    components" here. After all, what about all others
    tabes ? This is only one more, but I don't understand
    why want manage less objects, that implies more code,
    more maintenance, and more difficulties to debug.
    Needless to say about performance...
    Nicolas.The same reasons apply if you were forced to declare all PL/SQL variables publicly (outside the stored proc.) rather than privately (from inside the stored proc). Naming conflicts for one. If the name that you want to use for the GTT already exists, you need to find a new name. With the SQL Server type local/private declarations, you wouldn't have that problem.
    I can see how performance would be the same or better using GTTs. If the number of records involved is low, this is likely negligable.

  • Problem while calling webservice from a plsql stored procedure

    Hi everybody,
    I need to call a webservice from a plsql stored procedure.
    I was following documentation published in the otn at the following link.
    "http://www.oracle.com/technology/tech/webservices/htdocs/samples/dbwebservice/DBWebServices_PLSQL.html"
    I am encountering the following error on my sql prompt-
    SQL> exec dbms_output.put_line(time_service.get_local_time('94065'));
    BEGIN dbms_output.put_line(time_service.get_local_time('94065')); END;
    ERROR at line 1:
    ORA-29273: HTTP request failed
    ORA-06512: at "SYS.UTL_HTTP", line 1022
    ORA-12545: Connect failed because target host or object does not exist
    ORA-06512: at "APPS.DEMO_SOAP", line 65
    ORA-06512: at "APPS.TIME_SERVICE", line 13
    ORA-06512: at line 1
    Has anybody worked on the same example. Please direct me.
    Thanks & Regards
    Kiran Kumar

    Kiran, were you able to solve this?
    I am facing the same error.
    Oracle Server is Unix and webservice is .NET.
    I am able to connect to Java web service.

  • Calling a servlet from a Java Stored Procedure

    Hey,
    I'm trying to call a servlet from a Java Stored Procedure and I get an error.
    When I try to call the JSP-class from a main-method, everything works perfectly.
    Java Stored Procedure:
    public static void callServlet() {
    try {
    String servletURL = "http://127.0.0.1:7001/servletname";
    URL url = new URL(servletURL);
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestProperty("Pragma", "no-cache");
    conn.connect();
    ObjectInputStream ois = new ObjectInputStream(conn.getInputStream());
    Integer client = (Integer)ois.readObject();
    ois.close();
    System.out.println(client);
    conn.disconnect();
    } catch (Exception e) {
    e.printStackTrace();
    Servlet:
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    Integer id = new Integer(10);
    OutputStream os = response.getOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(id);
    oos.flush();
    oos.close();
    response.setStatus(0);
    Grant:
    call dbms_java.grant_permission( 'JAVA_USER', 'SYS:java.net.SocketPermission','localhost', 'resolve');
    call dbms_java.grant_permission( 'JAVA_USER','SYS:java.net.SocketPermission', '127.0.0.1:7001', 'connect,resolve');
    Package:
    CREATE OR REPLACE PACKAGE pck_jsp AS
    PROCEDURE callServlet();
    END pck_jsp;
    CREATE OR REPLACE PACKAGE BODY pck_jsp AS
    PROCEDURE callServlet()
    AS LANGUAGE JAVA
    NAME 'JSP.callServlet()';
    END pck_jsp;
    Architecture:
    AS: BEA WebLogic 8.1.2
    DB: Oracle 9i DB 2.0.4
    Exception:
    java.io.StreamCorruptedException: InputStream does not contain a serialized object
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java)
    The Servlet and the class work together perfectly, only when I make the call from
    within the database things go wrong.
    Can anybody help me.
    Thank in advance,
    Bart Laeremans
    ... Desperately seeking knowledge ...

    Look at HttpCallout.java in the following code sample
    http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/jwcache/Readme.html
    Kuassi

  • HELP!!! Problem of Calling external Web Service from a Java Stored Procedur

    1.I read the topic on http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/wsclient/Readme.html about Calling external Web Service from a Java Stored Procedur.
    2.After I import .jar to Oracle what is required by the topic,som error occued.
    Like: ORA-29521: javax/activation/ActivationDataFlavor class not found,
    ORA-29545: badly formed class.
    3.These is not enough .jar required on the topic? What can I do for ORA-29545: badly formed class?
    Thany you!

    Try this
    Re: HELP! Loading Java Classes into Oracle ERROR

  • Calling a URL from a Java Stored Procedure

    Hi,
    I'm trying to call a URL from a Java Stored Procedure in Oracle 8.1.7(Windows 2000). The ultimate goal is to call this stored procedure from a database trigger. The status of the object remains invalid in the database even after compilation and publishing without any errors. The code follows. Any suggestions/alternatives to accomplish this would be appreciated.
    Java Stored Procedure:
    CREATE OR REPLACE JAVA SOURCE NAMED "UPDATEATTR" AS
    import java.net.*;
    import java.util.*;
    import java.io.*;
    public class UpdateAttr {
    public static String testmain() {
    ObjectInputStream is;
    URL url;
    String uri =
    "http://www.yahoo.com";
    try {
    //calling the URL
    url = new URL(uri);
    URLConnection yahooConnection = yahoo.openConnection();
    } catch (Exception e) {
         e.printStackTrace(System.err);
    return "TEST_SUCCESSFUL";
    Code to Publish it:
    CREATE OR REPLACE FUNCTION setNewAttributes return VARCHAR2
    AS LANGUAGE JAVA NAME
    'UpdateAttr.testmain() return String';
    Thanks in advance.
    Ris

    Small mistake in the previous post. The object still has a status of "INVALID" though. The Java stored procedure should actually read:
    Java Stored Procedure:
    CREATE OR REPLACE JAVA SOURCE NAMED "UPDATEATTR" AS
    import java.net.*;
    import java.util.*;
    import java.io.*;
    public class UpdateAttr {
    public static String testmain() {
    ObjectInputStream is;
    URL url;
    String uri =
    "http://www.yahoo.com";
    try {
    //calling the URL
    URL yahoo = new URL(uri);
    URLConnection yahooConnection = yahoo.openConnection();
    } catch (Exception e) {
    e.printStackTrace(System.err);
    return "TEST_SUCCESSFUL";
    Code to Publish it:
    CREATE OR REPLACE FUNCTION setNewAttributes return
    VARCHAR2
    AS LANGUAGE JAVA NAME
    'UpdateAttr.testmain() return String';
    /

  • Connecting to a non-oracle database (jdbc) from a java stored procedure

    Does anyone know to configure the database to allow a connection to a non-oracle database from a Java Stored procedured, using JDBC?
    Thank you in advance,
    Chris

    Hi Chris,
    I haven't tried it, and these are just some of my thoughts, but I
    think you would need to load the JDBC driver for the other database
    into the Oracle database (using the "loadjava" tool, of-course).
    Then your java stored procedure should be able to instantiate the
    third party JDBC driver and obtain a connection to the other database.
    Hope this helps.
    Good Luck,
    Avi.

Maybe you are looking for