using LDAP url in JBOSS oracle-ds.xml - oracle

Our oracle servers are migrating to LDAP. I use JBOSS connection pooling in my application which looks like
<local-tx-datasource>
<jndi-name>OracleDB</jndi-name>
<connection-url>jdbc:oracle:thin:#dbs1:1521:SID</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>osuser</user-name>
<password></password>
</local-tx-datasource>
Now my DBA gave me a fully qualified LDAP url for the databse that is like server.db.company.com. Can you please suggest how do I use this url in the oracle-ds.xml?
P.S. I have already tried the URL as jdbc:oracle:thin:#ldap://server.db.company.com. It gives invalid LDAPexception.`

Related

JDBC connection to Oracle Database via Kerberos

I am trying to connect to an oracle database via JDBC and Kerbos within a tomcat.
Unfortunately I was not able to find anything useful on how to accomplish this.
My JDBC Connection looks like this:
<Resource name="jdbc/Oracle"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
maxTotal="40"
url="jdbc:oracle:thin:#10.1.1.1:1521/SERVICE"
/>
I know, that I have to work with Kerberos-Tickets here. But how to configure this? What Java options to set?

How do I pool Oracle connections in Tomcat?

I'm unclear on the appropriate way to set up connections to an Oracle RAC database in Tomcat via context.xml. THIS method works for me:
<Resource
name="jdbc/mydb"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:<connection details>"
username="<username>"
password="<account>"
maxTotal="150"
maxIdle="10"
/>
But is that using a connection pool? I tried adding factory="org.apache.tomcat.jdbc.pool.DataSourceFactory", as suggested at https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html, and mysteriously with that one change, I started getting:
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
If I instead try type="oracle.jdbc.pool.OracleDataSource" and factory="oracle.jdbc.pool.OracleDataSourceFactory" I get:
Error: Unable to obtain a JDBC connection from Datasource:
java.lang.Exception: Error: Unable to obtain a JDBC connection from Datasource:
I've looked all over, but it's not clear to me what the best practice is for this. Ideas?
I am adding this answer to clarify my earlier comments, and for future visitors to this question.
Summary
Both of the following approaches will use DB connection pools:
Use Tomcat's newer, default DBCP 2 pool with type="javax.sql.DataSource".
Use Tomcat's older JDBC pool with factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" and type="org.apache.tomcat.jdbc.pool.DataSource".
I don't know enough about the differences to give any strong recommendations re. using one over the other.
The Default DBCP 2 Tomcat Pool
To make use of the default Tomcat DB connection pool, via a JNDI resource, you should follow the instructions provided on this Tomcat documentation page: JNDI Datasource How-To
Specifically, you need to use type="javax.sql.DataSource".
Here is a very basic resource configuration - not suitable for production, but useful to illustrate the approach. And it's for MySQL not Oracle, so there will be some adjustments needed:
<Resource name="jdbc/my_db"
auth="Container"
type="javax.sql.DataSource"
initialSize="5"
username="db_user"
password="***"
driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mytestdb" />
When using initialSize="5", I saw the 5 expected connections on the DB server.
In the JVM, a connection pool was created - as shown in this VisualVM heap dump:
Here we can see that the pool is created, it has 5 connection objects, and it is using Tomcat DBCP - which, in turn, is a fork of Apache Commons DBCP 2.
DBCP 2 provides support for JDBC 4.1.
Tomcat's Home-Grown JDBC Pool
If you look at the Tomcat documentation on this other page - The Tomcat JDBC Connection Pool - you will see different guidance.
Specifically it states that you need both of the following in your <Resource>:
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
type="org.apache.tomcat.jdbc.pool.DataSource"
If you use this, you will also be using a DB connection pool - but it will be based on the older Tomcat JDBC pool package:
In this example, I used initialSize="3".
In the Tomcat documentation this is presented as "a new connection pool" (it was a replacement for the previously used Commons DBCP 1.x). It's not as new as the Tomcat default DBCP 2 solution. I think the documentation wording is out-of-date, now. And somewhat confusing, because of that.
Additional Notes
Notes from a member of the Tomcat commit team (see here):
Tomcat JDBC is Tomcat's "home grown" database connection pooling and does not use poolPreparedStatements
Tomcat DBCP is Tomcat's package renamed fork of Apache Commons DBCP 2.
Tomcat DBCP is used by default.
You can always choose to implement a pool directly in your code, without using a JNDI <Resource> annotation. There are many available options.
(In my initial tests, there was a problem with my Tomcat installation which resulted in the creation of too many connections for DBCP 2. That misled me, initially).
Oracle Universal Connection Pool (UCP) is a Java connection pool that you can use as well. It is feature rich and works well with Oracle RAC, DG etc., Check out UCPServlet for an example.

Connect Oracle cloud Database using JDBC java

I have database username and password to access oracle db and also have service url like https://X-X.X.X.oraclecloudapps.com/apex/.
Can anybody know how to connect this db using JDBC connection.
I tried using oracle thin driver but somehow it failes.
Sample java code:
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:#//X.X.X.X.oraclecloudapps.com:1521/sid", "username", "****");
It throws
Exception in thread "main" java.sql.SQLRecoverableException: Io exception: The Network Adapter could not establish the connection
I don't know SID here, it would be helpful if anybody give steps to find SID/ServiceName from Oracle Cloud dashboard.
You can't use JDBC to connect to the Database Schema Service. You can connect using the API or tools that utilize the REST API. For data upload to Oracle Database Schema Service, use Oracle SQL Developer, the Oracle Application Express SQL Workshop Data Upload Utility or the Oracle Application Express Data Load utility. Read more here: http://docs.oracle.com/cloud/latest/dbcs_schema/CSDBU/GUID-3B14CF7A-637B-4019-AAA7-A6DC5FF3D2AE.htm#CSDBU177
There is only three way to connect Database Schema Service.
From an Oracle Application Express application running in Database Schema Service
From a Java application running in an Oracle Java Cloud Service
Through RESTful Web services
Try the following JDBC URL to resolve the issue
"jdbc:oracle:thin:#host-address:1521/sid";
Note / is used after port and Not :

How to migrate WAS 7.5 to Liberty Profile 8.5?

I am looking to migrate my application to run on Liberty profile 8.5 instead of Websphere Application server 7.5. In this process, I need to do server configuration by setting up LDAP, Database source and JMS. As I am new to Liberty profile, I am looking for help in setting up these. May I get some suggestions from you to complete these settings?
This is a bit broad question, so I'll give you some pointers to documentation to get you started (There is no WAS 7.5, so you probably mean 7.0).
WebSphere Application Server Liberty Profile Guide for Developers - this will give you some basic general information to get you started with Liberty
Data source configuration - basic configuration is quite simple, you define it in server.xml file (you didn't mention which DB you are using, so here is sample with Derby)
<library id="derby">
<fileset dir="${shared.resource.dir}/derby"/>
</library>
<jdbcDriver id="derbyDriver" libraryRef="derby"/>
<dataSource jdbcDriverRef="derbyDriver" jndiName="jdbc/DataSourceJNDI" type="javax.sql.ConnectionPoolDataSource">
<properties.derby.embedded createDatabase="false" databaseName="D:\path\DB"/>
</dataSource>
For more specific information regarding migrating DB2 data sources see
Migrating a DB2 data source to the Liberty profile
LDAP configuration - basic configuration for MS Active Directory
<ldapRegistry id="ldap" realm="SampleLdapADRealm"
host="ldapserver.mycity.mycompany.com" port="389" ignoreCase="true"
baseDN="cn=users,dc=adtest,dc=mycity,dc=mycompany,dc=com"
bindDN="cn=testuser,cn=users,dc=adtest,dc=mycity,dc=mycompany,dc=com"
bindPassword="testuserpwd"
ldapType="Microsoft Active Directory">
<activedFilters
userFilter="(&(sAMAccountName=%v)(objectcategory=user))"&(sAMAccountName=%v)(objectcategory=user))"
groupFilter="(&(cn=%v)(objectcategory=group))"
userIdMap="user:sAMAccountName"
groupIdMap="*:cn"
groupMemberIdMap="memberOf:member">
</activedFilters>
</ldapRegistry>
For more details and other LDAP see Configuring LDAP user registries with the Liberty profile
JMS - as you didn't provide details, if you are acting as JMS server or client and which JMS provider are you using (default or MQ), check this page as starting point for JMS related configuration - Liberty profile: JMS messaging
Application migration - if you want to check, if there are any issues with your application code regarding migration, you can install plugin for Eclipse/RAD -
WebSphere Application Server Migration Toolkit – Liberty Tech Preview which will scan your code for incompatibilities.

WSO2 ESB 4.0.3 and governance registry configuration

I have one server running the ESB and another running the governance registry.
I am using the embedded h2 database. I can't connect the ESB to the Registry.
I get the following error
SQLNestedException: Cannot create JDBC driver of class 'org.h2.Driver' for connect URL
The jar with the the driver is in the path and works with a local h2 instance.
Any help appreciated
I believe this can be due to the h2 database not being able to accept multiple connections. But you need to provide more details to answer this question? Perhaps the entire stack trace. Usually, when we work with remote registries we use mysql or similar as the DB.
Since the h2 driver is shipped and it's already in the classpath anyway, it can't be due to a problem with the h2 driver, unless you changed the driver.

Resources