on 08-03-2006 4:59 AM
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.