Unable to connect and load data from Oracle, using Ignite V2.0 - java

I am trying to configure and read data from existing Oracle tables
However, I get error message while calling cache.loadCache(); this line.
It shows error message as
Message as
session:javax.cache.integration.CacheWriterException: Failed to start store
session [tx=null]Caused by: java.sql.SQLException: No suitable driver found
for jdbc:oracle:thin:#192.168.2.218:1521:xe at
org.h2.jdbcx.JdbcDataSource.getJdbcConnection(JdbcDataSource.java:190) at
org.h2.jdbcx.JdbcDataSource.getXAConnection(JdbcDataSource.java:351) at
org.h2.jdbcx.JdbcDataSource.getPooledConnection(JdbcDataSource.java:383) at
org.h2.jdbcx.JdbcConnectionPool.getConnectionNow(JdbcConnectionPool.java:226)
at
org.h2.jdbcx.JdbcConnectionPool.getConnection(JdbcConnectionPool.java:198)
at
CacheConfiguration<String, TempClass> cacheCfg = new CacheConfiguration<String, TempClass>();
cacheCfg.setName("Test_CacheConfig");
IgniteConfiguration igniteConfig = new IgniteConfiguration();
Factory<TempClassCacheStore> factory = FactoryBuilder.factoryOf(TempClassCacheStore.class);
cacheCfg.setReadThrough(true);
cacheCfg.setWriteThrough(true);
cacheCfg.setIndexedTypes(String.class, TempClass.class);
cacheCfg.setCacheStoreFactory(factory);
cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {
#Override
public CacheStoreSessionListener create() {
CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();
lsnr.setDataSource(JdbcConnectionPool.create("jdbc:oracle:thin:#192.168.2.218:1521:xe", "test", "test"));
return lsnr;
}
});
Ignite ignite = Ignition.start(igniteConfig);
IgniteCache<String, TempClass> cache = ignite.getOrCreateCache(cacheCfg);
cache.loadCache(null);
SqlFieldsQuery sql = new SqlFieldsQuery("SELECT ID_, NAME_ FROM TEST_TABLE");
QueryCursor<List<?>> cursor = cache.query(sql);
I have configured CacheStore for TempClass also as shown in
https://apacheignite.readme.io/docs/persistent-store#cachestore
Any help will be highly appreciated

As you're trying to load data from oracle to Ignite, you need to have Oracle JDBC Driver in classpath. Just put the driver JAR into IGNITE_HOME/libs folder prior to starting the nodes and run loading again.

Related

Not able to update document of mongodb by java application

I have Written a java code to update document in mongodb database my code is running msystem.out.println is getting print but the data is not getting updated
public static void main(String []args) {
MongoClient mongo = new MongoClient( Aws ip , port );
//Connecting to the database
MongoDatabase database = mongo.getDatabase("database");
//Creating a collection object
MongoCollection<Document>collection = database.getCollection("xyz");
//Updating a document
collection.updateOne(Filters.eq("_id", "60e53f4647c79a1db4821e4e"), Updates.set("comment", "IncorrectForm"));
System.out.println("Document update successfully...");
}
what can i do know ....

Connecting to MongoDB Atlas: com.mongodb.MongoCommandException: Command failed with error 8000

so I'm trying to connect to MongoDB Atlas Service, which is hosting my database (which i have done in the past with no problems), but I keep getting this error and I can't understand why. I cannot find anyone with the same issue, so I'm quite stuck.
Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 8000: 'not authorized on admin to execute command { insert: "adminCol", ordered: true, documents: [[{_id ObjectIdHex("5a4e3b6dd04f1c047975fdd5")} {id 512} {name peter jones} {hello hi}]] }' on server *******-shard-00-02-xygnn.mongodb.net:27017. The full response is { "ok" : 0, "errmsg" : "not authorized on admin to execute command { insert: \"adminCol\", ordered: true, documents: [[{_id ObjectIdHex(\"5a4e3b6dd04f1c047975fdd5\")} {id 512} {name peter jones} {hello hi}]] }", "code" : 8000, "codeName" : "AtlasError" }
at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164)
at com.mongodb.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:295)
at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255)
at com.mongodb.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:98)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:441)
at com.mongodb.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:76)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:189)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:263)
at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:126)
at com.mongodb.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:373)
at com.mongodb.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:255)
at com.mongodb.operation.MixedBulkWriteOperation.access$700(MixedBulkWriteOperation.java:66)
at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:199)
at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.OperationHelper.withReleasableConnection(OperationHelper.java:432)
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:190)
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:66)
at com.mongodb.Mongo$3.execute(Mongo.java:833)
at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1025)
at com.mongodb.MongoCollectionImpl.executeInsertOne(MongoCollectionImpl.java:513)
at com.mongodb.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:493)
at com.mongodb.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:487)
at AdminDB.addAdmin(AdminDB.java:51)
at AdminDB.main(AdminDB.java:76)
This is the code I'm using.
public class AdminDB {
private MongoDatabase adminDB;
private MongoCollection<Document> adminCollection;
private String adminCol = "adminCol";
public AdminDB() {
MongoClientURI uri = new MongoClientURI(
"mongodb://***********-shard-00-00-xygnn.mongodb.net:27017,*******-shard-00-01-xygnn.mongodb.net:27017,******-shard-00-02-xygnn.mongodb.net:27017/test?ssl=true&replicaSet=******-shard-0&authSource=admin");
MongoClient mongoClient = new MongoClient(uri);
adminDB = mongoClient.getDatabase("admin");
adminCollection = adminDB.getCollection(adminCol);
}
public void addAdmin(JsonObject json) {
adminCollection.insertOne(Document.parse(json.toString()));
}
public static void main(String[] args) {
AdminDB adminDB = new AdminDB();
JsonObject json = new JsonObject();
json.addProperty("id", 512);
json.addProperty("name", "peter jones");
json.addProperty("hello", "hi");
adminDB.addAdmin(json);
}
}
To clarify, MongoDB Atlas M0 (Free Tier), M2, or M5 shared starter cluster do not support read/write operations on any collections within the admin database. See also Command Limitations in Free Tier Clusters.
Change the database name to insert document into:
database = mongoClient.getDatabase("anotherDatabase");

Spring LDAP, setting connection details in java

I want to set LDAP connection to list all users from AD.
I successfully accomplished this with information stored in XML
<ldap:context-source
url="ldap://<url>"
base="dc=example,dc=local"
username="<user>#example.local"
password="<pass>" />
But how I can set this informations from Java, not in XML?
Tried with:
LdapContextSource ctxSrc = new LdapContextSource();
ctxSrc.setUrl("ldap://<url>");
ctxSrc.setBase("dc=example,dc=local");
ctxSrc.setUserDn("<user>#example.local");
ctxSrc.setPassword("<pass>");
LdapTemplate tmpl = new LdapTemplate(ctxSrc);
setLdapTemplate(tmpl);
But when runing
List users = (List<User>) ldapTemplate.search(LdapUtils.emptyLdapName(), "(&(objectCategory=person)(objectClass=user))", new UserAttributesMapper());
I get NullPointerExeption. Runing that without setting up properties from java (i.e. reading from xml) everything works fine
please try this
LdapContextSource ctxSrc = new LdapContextSource();
ctxSrc.setUrl("ldap://<url>");
ctxSrc.setBase("dc=example,dc=local");
ctxSrc.setUserDn("<user>#example.local");
ctxSrc.setPassword("<pass>");
ctxSrc.afterPropertiesSet(); // this method should be called.
LdapTemplate tmpl = new LdapTemplate(ctxSrc);
setLdapTemplate(tmpl);

Websphere Network deployment datasource

I have installed Websphere Network deployment server 7.0.0.0
I have configured a cluster on it.
I have configured a data source on it say ORA_DS this data source using "JAAS - J2C authentication data"
When i test the ORA_DS by clicking on "Test connection" button, the test connection is success.
The issue comes when i try to access this data source using my java code.
Here is my code to access data source and create a connection:
public class DSTester
{
/**
* Return the data source.
* #return the data source
*/
private DataSource getDataSource()
{
DataSource dataSource = null;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:9811");
// Retrieve datasource name
String dataSourceName = "EPLA1";
if (dataSource == null)
{
try
{
Context initialContext = new InitialContext(env);
dataSource = (DataSource) initialContext.lookup(dataSourceName);
}
catch (NamingException e1)
{
e1.printStackTrace();
return null;
}
}
return dataSource;
}
public static void main(String[] args)
throws Exception
{
DSTester dsTester = new DSTester();
DataSource ds = dsTester.getDataSource();
System.out.println(ds);
System.out.println(ds.getConnection());
}
}
Here is the output:
com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource#17e40be6
Exception in thread "P=792041:O=0:CT" java.sql.SQLException: ORA-01017: invalid username/password; logon denied
DSRA0010E: SQL State = 72000, Error Code = 1,017
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:406)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:799)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:368)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:275)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:206)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPhysicalConnection(OracleConnectionPoolDataSource.java:139)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:88)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:70)
at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper$1.run(InternalGenericDataStoreHelper.java:1175)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper.getPooledConnection(InternalGenericDataStoreHelper.java:1212)
at com.ibm.ws.rsadapter.spi.WSRdbDataSource.getPooledConnection(WSRdbDataSource.java:2019)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.createManagedConnection(WSManagedConnectionFactoryImpl.java:1422)
at com.ibm.ws.rsadapter.spi.WSDefaultConnectionManagerImpl.allocateConnection(WSDefaultConnectionManagerImpl.java:81)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:646)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:613)
at com.test.DSTester.main(DSTester.java:70)
The code works fine if i replace
ds.getConnection()
with
ds.getConnection("ora_user", "ora_password")
My issue is i need to get the connection without specifying login details for Oracle.
Please help me on this issue.
Any clue will be appreciated.
Thanks
I'd guess it would work if you retrieved the datasource from an application running on the WAS.
Try creating a servlet.
Context initialContext = new InitialContext();
DataSource dataSource = (DataSource) initialContext.lookup("EPLA1");
Connection con = dataSource.getConnection();
As within a servlet it is running within WAS it should be fine, if the "Test Connection" works. Running it outside is probably a different context.
I think you need to check all your configuration:
1) Is it application deplyed on cluster or into only one of cluster member?
2) JAAS - J2C authentication data - what is the scope?
Sometimes you need restar all your WAS environment. It depends on resource configuration scope
I'd recomend to you add resource refences for better configuration options.
SeeIBM Tech note

hibernate 4.2 schema based multi-tenancy + c3p0 connection pool

I am running a java app (java 1.7) with hibernate 4.2.0 and I need to implement a schema based multi tenancy setup. I used this exampleto do that.
my problem is that I was unable to figure out how to create the connection providers. the example uses:
acmeProvider = ConnectionProviderBuilder.buildConnectionProvider( "acme" );
jbossProvider = ConnectionProviderBuilder.buildConnectionProvider( "jboss" );
but ConnectionProviderBuilder is for testing use.
I tried to use the following:
C3P0ConnectionProvider connectionProvider = new C3P0ConnectionProvider()
{
public boolean supportsAggressiveRelease()
{
return allowAggressiveRelease;
}
};
connectionProvider.configure(props);
the problem here was that the C3P0ConnectionProvider has a null serviceRegistry which crush the with NPE.
does anyone have an idea on how to create ConnectionProvider for each tenant?
Thanks,
Ronen
Try suggestion using Properties to add data source properties:
DatasourceConnectionProviderImpl cp = new DatasourceConnectionProviderImpl();
cp.setDataSource(ds);
Properties p = new Properties();
// ...
cp.configure(p);
Or with DriverManagerConnectionProviderImpl:
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl() {
public boolean supportsAggressiveRelease() {
return allowAggressiveRelease;
}
};
connectionProvider.configure( props );

Categories

Resources