Retrieve iASP RDB name to specify it in jdbc url - java

I have a java application which runs on IBM i. It creates connection to AS400 database using jdbc. It does not specify the database name in JDBC connection URL, means it creates connection to default system database associated with *SYSBAS.
Now I want my application to run on iASP. When running on iASP it fails to connect to database.
IBM i documentation says that we must specify RDB name in "database name" property of jdbc connection URL to connect.
problem here is that,
IBM i documentation says by default RDB name of iASP group is same as primary iASP device name in iASP group. But it can be assigned different name.
I am able to retrieve iASP group name and iASP device name programmatically using JTOPEN(by calling API QUSROBJD). Which means my application will work in default scenario. But when RDB name is assigned different name then my application may fail. I want to retrieve RDB name associated with iASP.
How can I retrieve correct RDB name for an iASP?
I tried using API QUSRJOBI, but it is returning database name as blank.

There are two types of Auxiliary Storage Pool (ASP) on IBM i: System ASPs and independent ASPs (iASP). On DB2 for i, all libraries in the system ASP are treated as a single database and you can qualify tables with a schema name to access a tables in a specific library. According to the documentation that I found, each new iASP creates a new database, and these can be queried in QSYS2.SYSCATALOGS. So you will need a connection to the system database and, from that, you can find the database name and connect to each iASP that you need a connection to. Unfortunately I cannot test this as I do not have an iASP available to me.

Related

I am having problem connecting to Oracle SQL Developer HR Database

I have just installed Oracle SQL Developer and I am trying to connect to HR Database for the first time. I tried default username "System" and password "system", "sys", "oracle" but none of them are working. I am using Arch Linux. The Screenshot of the error is attached as well. The Error message is
Status : Failure -Test failed: IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=ZrfViTiuQUyVFaAIdM2Sxg==)
What you may know as a distinct "database" in other db products is known as a "schema" in Oracle. You are trying to connect to the HR schema rather than the HR database.
A schema has an owner (user). To "connect to a schema" you must connect as the schema's owner. So, the Username you should use is HR - not SYSTEM or anything else. Also, the (default) password for this user is HR.
The "Name" field is for the name you want to give to this connection; most likely it should also be HR. It is asking you for a "name" because you are only setting up a connection in SQL Developer; you may create different connections, with different settings, to the same schema! In your case though you probably just want one connection to HR for now, and it makes sense to name the connection HR as well.
You may run into additional problems. First, in more recent versions, the Oracle database you download and install may not include the HR schema; you may need to add it after the fact.
Second, you may need to use a Service name rather than a SID - depending on your db version. And you may need to learn about "container" and "pluggable" databases, unless you installed the database with the non-CDB option; the default is the CDB (multi-tenant) option.

Reverse Engineer JDBC Oracle Connection String

Through my research, I wasn't able to find a duplicate of this question (a similar format wasn't include in any of these answers), but please mark it as such if it already exists.
I have the following JDBC connection string to connect to an Oracle database that I am trying to reverse engineer to connect elsewhere, but I don't know which components are server and which are database.
jdbc:oracle:thin:#word1://word2:port/word3,cn=word4,dc=word5,dc=word6
This was used to connect as part of a Sqoop job. The username and password are provided separately, so I don't believe any of these components are username or password. Could someone help me map these words and what their use case is?
Are any of these the database?
To reverse engineer this URL you start with #word1.
According to the Oracle documentation (see reference below), the part of the URL following the jdbc:oracle:thin: is the data source. There are a variety of different data source types, and the syntax of the next first component (including the # if present) will determine the type. The documentation lists the following data source types:
Oracle Net connection descriptor - #(...)
Thin-style service name - name#
LDAP syntax - #ldap
Bequeath syntax - oci:path/#
TMSNames alias - #name
If there was no more context, you just read the documentation to decode the rest of the URL, per the data source type.
But you have revealed that there are cn and dc parameters in the URL. That makes it 99.9% likely that this is actually an #ldap data source.
The structure of an JDBC URL with an LDAP data source is:
jdbc:oracle:thin:#ldap://<host>:<port>/<name>,<ldap context param>...
where <host> and <port> are for an LDAP service, and the ldap context parameters are a list of name=value pairs which should include cn=OracleContext.
This tells the JDBC driver to lookup <name> in the LDAP server with the given context, and then use the associated information to establish the database connection. I couldn't find a definitive reference for what <name> actually is. The Oracle documentation just gives an example.
The best I could find is this:
Database Service Name: The database service name tells the driver what database to connect to. For example, if the database is named "dmart", dmart should be entered as the database service name.
(Source: https://razorsql.com/articles/oracle_ldap_jdbc_connect.html)
The "#ldap" can replaced by "ldaps:", which means LDAP over SSL.
References:
Database JDBC Developer's Guide and Reference, Data Sources and URLs

DB2 JDBC connection url with instance name

Current JDBC URL using looks like
jdbc:db2://server:446/DBname
Want to connect to a different instance by providing the instance name.
How should be the connection string for this?
In jdbc you do not connect to an instance, instead you connect to a database. It is possible to ATTACH to a DB2-instance but normally you don't want to do that unless you are a DBA. To specify a different DB2-instance, mention its hostname(or IP-address, or Virtual-IP-address) and its port-number. If a hostname runs multiple DB2-instances, each DB2-instance will have a unique port-number on that hostname.

Glassfish JDBC Connection pool - specify specific schema name

I'm trying to set up a JDBC connection pool (WITH username and password)
However, the the schema name (which obviously wasn't set up by myself) was named something else and NOT the same as the username. Therefore, when my Glassfish web app runs, I got "unknown table or view" error.
I figure I can address this by hard-coding the schema on each and everyone of my entity classes, BUT I was wondering if there's a way to specify this in either in the JDBC connection pool or the JDBC resource that my application is using.

No effect of setting instance name in jdbc connection string

I am trying to connect to SQL server 2005 via Workbench/J. I entered everything correctly for the jdbc string and I can connect to the desired server. But, I have to type fully qualified names for a table with database name. I don't want to do that. I set my instanceName to the database and it did not work for me.
Is there a way to connect to the DB instead of just the server ?
jdbc:sqlserver://serverName[\instanceName][:portNumber]
If you want to connect to an instance you need to do two things:
Make sure the SQL Server Browser service is running on your SQL Server host (disabled by default IIRC)
Do not include the portnumber in the connection string if you want to connect by instance name. The JDBC driver will ignore the instance name when the connection string includes a portnumber (each instance has its own port number)
With regard to the second item, the documentation says:
For optimal connection performance, you should set the portNumber when you connect to a named instance. This will avoid a round trip to the server to determine the port number. If both a portNumber and instanceName are used, the portNumber will take precedence and the instanceName will be ignored.
The instance name is not the same thing as your database name. You specify the database name using the connection property databaseName, eg:
jdbc:sqlserver://localhost;databaseName=AdventureWorks
Microsoft SQL Server supports multiple installs on the same computer. Each install ("virtual" SQL Server, if you will) is identified by its "Instance name". So, we could have two separate "SQL Servers" on the same computer, e.g., one instance named \PRODUCTION for the production databases, and another instance named \TEST for a test environment. Each instance operates independently.
A default installation of SQL Server Express Edition creates a SQL Server instance named \SQLEXPRESS. The other Editions of SQL Server normally create a "default instance" (sometimes identified as \).
Each instance of SQL Server can contain multiple databases. You can set the default database for your connection like this:
jdbc:sqlserver://myservername;database=myDb
or
jdbc:sqlserver://myservername;instanceName=instance1;database=myDb
I think you should be able connect to a specific database like this:
jdbc:sqlserver://serverName[\instanceName][:portNumber];databaseName=MyDatabase

Categories

Resources