How to connect to an Oracle database with JDBC - oracle

I currently have a connection for MySQL database and connected as:
spring.datasource.url = jdbc:mysql://${mysql.service.host}:${mysql.service.port}/${mysql.service.database}
If I were to change the database and used Oracle database instead then how would the datasource URL change?

jdbc:oracle:thin:#//server:port/service
or
jdbc:oracle:thin:#//server:port:SID
The server entry would be the IP address or network name where your Oracle Listener is handling connection requests. The port would be the port number being used for said listener requests.
Service would be the database service name, if you're connecting to an Oracle Pluggable Database, you'll always need this.
The SID is a unique ID for your database, you could use that, but you're encouraged to use the service instead.
If you wish to make a THICK connection, that is, use an Oracle Client to make a connection to your database, then things get a bit more complicated. I would suggest using THIN until you can't.

Related

How to connect to an Oracle database through VS Code using an SID instead of Service Name?

I'm trying to see if I can use VS Code to connect to the Oracle databases we use at my job. I installed the Oracle Developer tools extension for VS Code, but when I click to add a connection it is required that I use a service name.
VS Code Oracle Connection Form
Does anyone know of a way I can use SID instead of a Service Name? All of our connections use SID.
I've tried the different options for connection type, however they all ask for fields that are not required of me to connect to the db. I've also used the SID as the Service Name, but was still unsuccessful in connecting.
All of our connections use SID.
is something you should be looking at addressing as a side project. Services over SID became recommended in Oracle 8i (yeah you read that right...20 years ago)
But every database has an implicit service name equivalent to the SID so just entering the SID value should still get you connected without issue.
Of course, now that we're in the world of pluggable databases, this will pretty much force your organisation to move to services, because the SID is typically going to point to the root container whereas you will want to connect to the pluggable(s) that sit underneath it.

If Oracle dblink is set, can the configured external DB also access my DB?

If Oracle dblink is set, can the configured external DB also access my DB?
Is there a way to check which external db is allowed to dblink to my DB?
DB Links are one way: one DB (with the link) is the client and the other DB is the server in the relationship, and the server cannot reach back to the client for data or any other information not normally available from any client (basic connection info is made available by the client through the Oracle Client software API).
There is no server-side privilege that specifies whether a client connection may or may not be from a DB Link or any other specific source: any valid database server account can be used as a link target, just like connecting from any other client. There is a client-side privilege CREATE DATABASE LINK that determines whether the link object can be created on the client side.

GCP Datafusion oracle connectivity issues

We're currently having issues setting up a connection to oracle datasources in datafusion (via jdbc) and i'm not sure if i am missing something.
Bit of a background, we had issues connecting to any data source initially so in gcp i setup a vm instance to act as a proxy server (due to it being a private datafusion instance) and used iptables to register the connections.
After this i can successfully connect to sql server datasources, on the vm instance i can ping and telnet all oracle and sql datasources.
Network connectivity tests show datafusion can connect to the proxy and also that the proxy can hit datasources on-prem.
The following pics are of my connection to oracle under namespace admin in datafusion
The ip address is of the proxy instance and the port is what was assigned in the iptable entry
Again this works for sql server. Our datateam can connect to these datasources via bigquery using odbc, but it looks like you cannot use that connection type in datafusion.
Think we have resolved the issue. We noticed the logins being used had older password versioning for oracle 10, 11 etc. Got the oracle dba to create a new user to test and connection successful instantly :)

Discover oracle connection data (Host, SID/Service, Port) from an ODBC connection

I'm not an Oracle guy, but I find that I need to touch on some oracle resources to respond to a new report request. I'm working at an office where the connection to an oracle server uses LDAP and I can't get to the connection info. I do have an ODBC connection on my machine, so I can get into the database through MS Access. But I'd like to be able to connect with SQL Developer so I can do more useful profiling on the tables.
Is there any way to use my ODBC connection through Access to tease out Hostname, Port, and SID/Service name so I can connect through SQL Developer?
It seems I do not have permissions to the UTL_INADDR functions.
Since you have an ODBC connection defined already, you can open the ODBC Data Source Administrator on your computer (Goto the start menu and type ODBC in to search for it).
In the ODBC Data Source Administrator select the data source for the database in question (it may be on the User, System or File DSN tab) and click the Configure button.
From the Configuration screen you will be able to see the TNS Service Name for the connection.
The TNS Service Name should be all you'll need to supply to SQL Developer when creating the connection. Aside from your account credentials of course.
You can query SID and Hostname like this:
select instance_name, host_name from v$instance;
Afaik there is no way to query the port name from the database, see also this article on Ask TOM on this subject:
You cannot get the port -- the port is not necessarily known to the
database. The listener need not be running on the same machine with
the database, a single listener might be servicing many databases. A
database may have many listeners servicing it.

What is the difference? Oracle TNS SID Listener

In human language: What is the difference between: TNS, SID and a Listener? Thanks!
SID aka ORACLE_SID identifies the processes running an instance for the database. It is a physical kind of identifier. RAC databases typically have multiple instances and there for use multiple ORACLE_SID's. SID's can be used to connect to the specified database instance. If that instance is down, the connection fails.
SERVICE_NAME is a logical identifier where clients can connect to, instead of connecting to a SID. Especially in a RAC database, it can happen that a service is running on only a subset of the instances of the database. When using services, the application does not need to know on which ORACLE_SID the requested service is provided. Also, with services you can limit access to your database by disabling a service during maintenance. The ORACLE_SID is always available and can only be put in a restricted mode, limiting all access to the full instance. When an application uses services and as long as at least one instance is serving the service_name, a connection to that service succeeds.
TNS Tranparent Network Substrate, a location transparent and protocol independent network technology. The location transparency is made by using services and in the database a combination of synonyms and database links.
SID: Site Identifier: The Unique name of your database. +/- database instance with multiple databases running on that instance.
Service Name: Alias to an instance (SID)
TNS: Transparent Network Substrate: Oracle relies on TNS to provide network connectivity between Oracle databases, regardless of underlying protocols. This is an oracle network technology that is user-transparent.
These 3 are completely different things in Oracle terms:
- Transparent Network Substrate (TNS) is an Oracle networking technology that provides generic network connectivity between Oracle databases and Oracle clients, regardless of underlying protocols (TCP, etc.)
- SID - Oracle System Identifier that represents a unique name for an Oracle database instance on a specific host. A standalone database has one SID and it's usually but not necessarily identical to a database name. in RAC database every database instance has its own SID.
- Listener - A process that listens for incoming client connection requests and manages network traffic to the database.

Resources