on 12-27-2005 2:21 PM
I have a requirement, where i need to create Data Source dynamically through my Java Program (in this case i can not use Visual Administrator). Can anybody help me in finding which java package needs to called to create a DS.
Thanks
KP
Hi,
The code you are using creates and odbc datasource.
I am not sure if the odbc datasource is visible in visual administrator.
The odbc datasources are usually seen in administrative tools(control panel)
In any case it may be possible to view /create different datasources in visual administartor.
Please refer this link,this gives a good idea aout datasources on Visual administrator.
http://help.sap.com/saphelp_nw04/helpdata/en/c0/3ad4d5cdc66447a188b582aad537d3/frameset.htm
Regards,
Harish
(Please award points for helpful answers)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You do not want to create datasources by code.
<b>They need to be defined in the apps deployment descriptor</b>, and the access to the DS could not be dynamic in any manner as you need to be able to retrieve it from the context... So you cannot bind DS1 as myds into the context and next minute replace it with DS2 as the thread xyz would expect DS1 and get DS2....
Using a Datasource outside of an Appserver does not give you the resource pooling features provided by the J2EE container.
And by the way there was a crucial piece of information missing in the exemple above. To define a DataSource you need a jdbc driver class.(Preferably jdbc 4 compliant).
Enjoy
Hi,
The code fragment VendorDataSource was a general name I just gave ,if you are using the class sun.jdbc.odbc.ee.DataSource class,
You must write the code as follows,
<%@ page language="java" import =
"java.util.*,javax.naming.Context,javax.naming.InitialContext,javax.naming.Name,javax.naming.NamingException,javax.rmi.Portab
leRemoteObject,sun.jdbc.odbc.ee.*" %>
<%
sun.jdbc.odbc.ee.DataSource ds = new sun.jdbc.odbc.ee.DataSource();
ds.setServerName("my_database_server");
ds.setDatabaseName("saurabh");
ds.setDescription("the data source for inventory and personnel");
Context ctx = new InitialContext();
ctx.bind("jdbc/saurabhDB", ds);
%>
You can find the the given sun.jdbc.odbc.ee.DataSource in the jar file rt.jar .This is naturally part of the recent versions of jdk released by sun.
This should solve the problem
Regards,
Harish
(Please dont forget to award suitable points,thanks in advance)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Here is a general code to create a new datasource.
VendorDataSource vds = new VendorDataSource();
vds.setServerName("my_database_server");
vds.setDatabaseName("my_database");
vds.setDescription("the data source for inventory and personnel");
Context ctx = new InitialContext();
ctx.bind("jdbc/AcmeDB", vds);
If you are using sun for the Vendor,
what you need to do is use sun.jdbc.odbc.ee.DataSource as the VendorDataSource,
For further information , you can use the link
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/bridge.html
Regards,
Harish
(Please award points ,if this answer has been helpfull)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi harish,
thanks for the reply.
can u tell me which class to import for using "VendorDataSource" for SQL Server.
I m going to create and register my datasource on WAS.
I tried using "sun.jdbc.odbc.ee.DataSource " as per ur mail but i got the follwoing error:
com.sap.engine.services.servlets_jsp.server.jsp.exceptions.CompilingException: Error while executing the compilation process: C:/usr/sap/WAS/JC00/j2ee/cluster/server0/apps/sap.com/wise/servlet_jsp/wise/work/jsp_DMAddDBSource1135753532996.java:50: cannot resolve symbol
symbol : class VendorDataSource
location: class jsp_DMAddDBSource1135753532996
VendorDataSource vds = new VendorDataSource();
^
C:/usr/sap/WAS/JC00/j2ee/cluster/server0/apps/sap.com/wise/servlet_jsp/wise/work/jsp_DMAddDBSource1135753532996.java:50: cannot resolve symbol
symbol : class VendorDataSource
location: class jsp_DMAddDBSource1135753532996
VendorDataSource vds = new VendorDataSource();
^
Here is the code from my JSP :
<%@ page language="java" import =
"java.util.*,javax.naming.Context,javax.naming.InitialContext,javax.naming.Name,javax.naming.NamingException,javax.rmi.Portab
leRemoteObject,sun.jdbc.odbc.ee.*" %>
<%
VendorDataSource ds = new VendorDataSource();
ds.setServerName("my_database_server");
ds.setDatabaseName("saurabh");
ds.setDescription("the data source for inventory and personnel");
Context ctx = new InitialContext();
ctx.bind("jdbc/saurabhDB", ds);
%>
Pls help.
Regrds
Saurabh
Hi,
I created the context and added a subcontext to it and then added my datasource to it successfully.
I tried to look it up in Visual Administrator but the datasource is not visible under the root.
could u pls tell me where it could have been created.
Following is the code that i used to create context and add datasource to it.
<%@ page import='java.util.*' %>
<%@ page language="java" import =
"java.util.*,javax.naming.Context,javax.naming.InitialContext,javax.naming.Name,javax.naming.NamingException,javax.rmi.Portab
leRemoteObject,sun.jdbc.odbc.ee.* " %>
<%
sun.jdbc.odbc.ee.DataSource ds = new sun.jdbc.odbc.ee.DataSource();
ds.setDatabaseName("jdbc:microsoft:sqlserver://172.22.76.8:50000/WAS");
ds.setDataSourceName("saurabh");
//ds.setServerName("my_new_database_server");
//ds.setPortNumber("940");
//ds.setNetworkProtocol("jdbc:microsoft:sqlserver://127.0.0.1:1433");
ds.setUser("sa");
ds.setPassword("sa");
ds.setDescription("the data source for inventory and personnel");
Context ctx = new InitialContext();
ctx.createSubcontext("saurabh");
ctx.bind("saurabh", ds);
%>
Could u pls help on this .
Regards
saurabh
User | Count |
---|---|
81 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.