How to connect to Oracle DB from Ubuntu Linux.

Posted by on in Programming

How to connect to Oracle DB using Delphi FireDAC.

Delphi uses Linux(64). and Linux is ubuntu.

I used "Oracle SE One" of AWS(RDS).

 

[Instant Client download]

Download 12.2 Instant Client. 

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

I downloaded instantclient-basic-linux.x64-12.2.0.1.0.zip

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html#ic_x64_inst

 

Unpack it after placing it on Linux. 

#
unzip instantclient-basic-linux.x64-12.2.0.1.0.zip

Create a directory and place the decompressed file.

 instantclient_12_2 directory is made.

#
mkdir /opt/oracle
mv instantclient_12_2 /opt/oracle/

Move this to the directory created.

Create a link.

#
ln -s libclntsh.so.12.1 libclntsh.so
ln -s libocci.so.12.1 libocci.so

 

Setting environment variables.

#
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH
export PATH=/opt/oracle/instantclient_12_2:$PATH

 

At this point, Instant Client configuration is complete.

Finally, "./PAServer-19.0/paserver" is started up and ready.


 

 

[Create a new project.]

In Delphi IDE side, create a new project. Web Server Application, check Linux.

I chose "stand-alone console application" this time.

Place some components on TWebModule1.

TFDConnection, TFDPhysOracleDriverLink, TFDQuery, TFDStanStorageJSONLink

Return the contents acquired by FDQuery1 with JSON. Write the code.

There is a simple table and some records on DB side.

////
procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  ms_:  TMemoryStream;
begin
  FDQuery1.Active := True;
  ms_ := TMemoryStream.Create;
  FDQuery1.SaveToStream(ms_, TFDStorageFormat.sfJSON);
  ms_.Position  := 0;
  Response.ContentStream  := ms_;
end;

procedure TWebModule1.WebModuleCreate(Sender: TObject);
begin
  FDPhysOracleDriverLink1.VendorLib   := '/opt/oracle/instantclient_12_2/libclntsh.so';
  FDConnection1.Connected := True;
end;

 

When executing debugging, the following option is mandatory.

"/usr/bin/xterm -e "%debuggee%""

 

 

 

[In case of failure.]

////
Project raised exception class EFDException with message '[FireDAC][Phys][Ora]-314. Cannot load vendor library [libclntsh.so]. Hint: check it is in the PATH or application EXE directories, and has x64 bitness.'.

Failure Review the environment on the Linux side.

 

[In case of success.]

 

The content saved by JSON of FDQuery1 is displayed.

 

 

 

 

 



About
Gold User, No rank,
Delphi / C++Builder blogger

Comments

Check out more tips and tricks in this development video: