RSS Feed for This PostCurrent Article

Dynamically Import Data from Different Oracle Databases from Web Application

Download Source

Sometimes back when I was involved in a project I faced the challenge to import data from different Oracle databases synchronously within my Java web application. Performance is the key issue. The import has to be completed in a short time frame according to the SLA.

Of course I can dynamically create JDBC connection to the database and retrieve the data that I wanted, but it proved to be very slow.

Since all the databases are Oracle, I tried to use PL/SQL. After some trials and errors, finally I create an Oracle package which can do the following

  1. Dynamically create a database link to the source database
  2. Execute insert select statement in parallel to import from the source table to the target table.

Since all the data import is done on the database level, and fully making use of the multiprocessor server, the performance proved to be very satisfactory.

Below are some of the code snippets that I used to link and unlink from the database.

function LinkDatabase(hostName varchar2,portNumber varchar2, sid varchar2,
dbUsername varchar2, dbPassword varchar2)
return varchar2 is

dbLinkName varchar2(100);
connString varchar2(500);
begin
dbms_output.enable(1000000);
— Assign the link name
dbLinkName:= DATABASE_LINK_PREFIX || sid;
begin
— Drop existing database link, ignoring any errors returned
execute immediate ‘DROP PUBLIC DATABASE LINK ‘ || dbLinkName;
exception
when others then
null;
end;
connString:= ‘CREATE PUBLIC DATABASE LINK ‘ ||
dbLinkName ||
‘ CONNECT TO ‘ ||
dbUserName ||
‘ IDENTIFIED BY ‘ ||
dbPassword ||
‘ USING ”(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = ‘ ||
hostName ||
‘)(PORT = ‘ ||
portNumber ||
‘)) (CONNECT_DATA = (SID = ‘ ||
sid ||
‘)))”’;

–dbms_output.put_line(connString);
execute immediate connString;

return dbLinkName;

exception
when others then
ErrHandler.log;
RAISE;
end;

—————————————————————
procedure UnLinkDatabase(linkName varchar2) is
begin
dbms_output.enable(1000000);
begin
— Drop existing database link, ignoring any errors returned
execute immediate ‘DROP PUBLIC DATABASE LINK ‘ || linkName;
exception
when others then
null;
end;

end ;


Trackback URL


Sorry, comments for this entry are closed at this time.