0

I am writing a standalone Java program which makes JDBC connection to a Websphere server. Websphere app server already have Datasource configured (we using JCA) and its running fine. Now, When I run my standalone code (from RAD/Eclipse) to get connection, it gives me error on line dataSource.getConnection();

error : java.sql.SQLException: invalid arguments in call DSRA0010E: SQL State = null, Error Code = 17,433

I searched for this error, many people suggested to pass user/pwd in connection like dataSource.getConnection(user, pwd). I did tried that and it worked fine. I am able to get the jdbc connection and my app works fine.

Problem: I can not pass hard coded user and password in my application. because usr/pwd can be changed in future or its a security breach.

Someone please suggest me. why its not able to pull connection through jca and why it need password?

` Properties localProperties = new Properties(); localProperties.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"); localProperties.put(Context.PROVIDER_URL, "iiop://xxx.xx.xx.net:28035");

InitialContext localInitialContext = new InitialContext(localProperties); DataSource localDataSource = (DataSource)localInitialContext.lookup(datasource);

//localConnection = localDataSource.getConnection("user","mypwd"); // works fine localConnection = localDataSource.getConnection(); // Do not work `

AmitG
  • 519
  • 6
  • 19
  • If you need more options for authentication maybe you need to look at going with an EE client. It's more heavyweight than a simple Java main, but I believe it does provide this capability. Maybe start with: https://www-01.ibm.com/support/knowledgecenter/SSAW57_7.0.0/com.ibm.websphere.nd.doc/info/ae/ae/tatk_condacli.html – Scott Kurz Nov 11 '15 at 15:28
  • After struggle I came to conclusion that my concept was not right about connection. Mistake is one can not get connection from a websphere JCA unless passing usr/pwd or the application code it shelf is deployed on the server. So if I do not want to pass hard coded password, then I need to deploy the code on server. Then only JCA can give me connection, else its a security breach obviously.. – AmitG May 09 '16 at 15:15

5 Answers5

0

I'm sure that is there a small mistake somewhere in the Data Douce configuration.

Is your test connection working fine in Websphere data source ?

Is your J2C entries are correct ?

Also to take note you should be running on Websphere context to get the datasource from Websphere.

  • Thanks Jagan for reply. I do have connection working on WAS and J2C is correct. Because its my main application server and it works fine. – AmitG Nov 11 '15 at 14:35
  • Actual Question is when I put the user/pwd in getConnection() then it worked. But I do not want hard coded password to set in code. So is there something I am missing while getting context? or something special for J2C. – AmitG Nov 11 '15 at 15:04
0

Usually you should be in a Websphere context to get the InitialContext to lookup JNDI for datasource.

Not sure - if you standalone program can do that.

Can share the code snippet ?

0

There is an other thread related to this.

Ref this question:

Access the DataSource from the stand alone application

But according to my understanding - data sources are only local you cannot do a remote lookup (like remote EJB lookup).

Seems this is working - access via getConnection(username, password).

Community
  • 1
  • 1
  • The other thread did not reach to conclusion. He is passing usr/pwd from code. Which I do not want. – AmitG Nov 12 '15 at 13:33
0

I did this check my self - not within eclipse or RAD.

But in a common server environment - with all the jars available on my class path.

I was not able to lookup my JNDI as it says you are not kind of valid client to access.

But I can my EJBs with remote stuff.

If you still want to use the Websphere datasource configuration - I prefer you to take a look at JSR-352 implementation - Java batch. Or an EJB with timer execution or Executor service.

E.g. https://developer.ibm.com/wasdev/docs/creating-simple-java-batch-application-using-websphere-developer-tools/

0

(Adding my earlier comment as an answer) You should be able to do this with an EE client. This is more heavyweight and involved, but in return you get more flexibility with the authorization config. Maybe start with: https://www-01.ibm.com/support/knowledgecenter/SSAW57_7.0.0/com.ibm.websphere.nd.doc/info/ae/ae/tatk_condacli.html

Scott Kurz
  • 4,985
  • 1
  • 18
  • 40