cancel
Showing results for 
Search instead for 
Did you mean: 

How to get datasource from SAP WAS 6.40 from standalone java?

Former Member
0 Kudos

I've created a standalone Java program to connect to my DB. I wish to get the Datasource object from my SAP WAS 6.40 and used it in my standalone program. How can I do this? Is there any API provided by SAP for me to get the Datasource object? If yes, where can I get the API?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

it involvs the same steps as required for EJB client programs i.e.

// set the properties for the InitalContext
final String USER = "Administrator";
final String PASSWORD = "abcd1234";
final String SAP_NAMING_PROVIDER_URL = "localhost:50104";
final String SAP_INITIAL_CONTEXT_FACTORY_IMPL =
"com.sap.engine.services.jndi.InitialContextFactoryImpl";
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,			SAP_INITIAL_CONTEXT_FACTORY_IMPL);
properties.put(Context.PROVIDER_URL, SAP_NAMING_PROVIDER_URL);
properties.put(Context.SECURITY_PRINCIPAL, USER);
properties.put(Context.SECURITY_CREDENTIALS, PASSWORD);

InitialContext context = new InitialContext(properties);
// Retrieve a DataSource object using JNDI
 DataSource ds = (DataSource)context.lookup("JNDINAME");
// Retrieve a connection from the datasource
 Connection c = ds.getConnection();
// Your normal JDBC stuff....

Hope this helps..

Rgds,

Amol

Former Member
0 Kudos

Where can I get the jar file containing 'com.sap.engine.services.jndi.InitialContextFactoryImpl' class?

Former Member
0 Kudos

its sapj2eeclient.jar , search your webAS installation folder usr/sap/<SYSID> for this jar file

Former Member
0 Kudos

How do I know the port no? localhost:50104? How do I know which port should I use?

Former Member
0 Kudos

get in touch with your basis guys and ask them for P4 provider port which can be seen in Visual administrator

Former Member
0 Kudos

base line is:

You cannot create your app as a standalone java and expect to retrieve the jdbc datasource from SAP.

Your app needs to make its own jdbc setup and possibly create its own context....

The right way would be to set it up as a J2EE client app and you will have to use the full weight of the J2EE client. This way you can tap into the full J2EE remote context and use it.

Enjoy

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Try This

Class.forName("<DriverName>");

conn= java.sql.DriverManager.getConnection("<DataBase>//<ServerIP>:<Port>;user=<UserName>;password=<Password>;database=<DataBaseName>");

for Eg:

<Driver>="com.microsoft.jdbc.sqlserver.SQLServerDriver";

<Database>="jdbc:microsoft:sqlserver:";

Kind Regards

Mukesh