cancel
Showing results for 
Search instead for 
Did you mean: 

How can i get DB connetion from myself datasource....

Former Member
0 Kudos

HI!

J2EE engine default datasoure is connecting to SAP DB,i want to use sybase ,when i create a new datasource ,how can i get the connetion of sybase db,if anyone give the step and java code wirtten in WebDynpro...such as :


Context ctx = new InitialContext();
DataSource ds =  (DataSource)ctx.lookup("mySybase");

if (ds==null) {
	throw new Exception("DataSource is null");
}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ree,

have you already data source and an alias for sybase DB on your server defined? When yes i think you sholud loking for data source with:

   ctx.lookup("jdbc/<your alias for synase>")

Regards

Bogdan

Former Member
0 Kudos

THX B.R. very much, The datasoure has been define on the server,

datasource alias is "mySybase",

i have test the code for this:


DataSource ds =  (DataSource)ctx.lookup("jdbc/mySybase");

bu i can't make it work too....

i thought there is some setup i have ignored!

Former Member
0 Kudos

ree,

i have two questions:

Can you see your alias in VisualAdministrator (service JNDI registry) in node jdbc?

What happens when you have called the lookup method (naming exception?) ?

Bogdan

Former Member
0 Kudos

Ree,

one more point to check. Have you declared in ejb_jar.xml a resource-ref for ejb which use this DataSource?

Bogdan

Former Member
0 Kudos

Hi,

I guess u can use "jdbc/mySybase" only if the alias name is defined in Persistent.xml, like for SAPDB. Else u will require a driver to connect to the DB.

Regards,

Piyush.

Answers (2)

Answers (2)

0 Kudos

Just wondering if you managed to get the datasource working?

I just installed a SQL Anywhere database and was able to get the datasource configured/connected and now I'm having trouble with execution of a stored procedure. You said that you got the datasource connected, are you able to monitor the connection from within the Visual Administrator? What kind of SQL Engine did you specify? I had to specify "Vendor SQL" in order for the connection to initialize. When I try to close the connection, it blows up? Is it possible to use straight JDBC code or do you have to use the com.sap.sql.NativeSQLAccess classes?

...Scottd

Former Member
0 Kudos

hi,i met the same problem.

i can get an connection of sybase driver with this way(coder in webdynpro implementation):

-


......

try {

DriverManager.registerDriver(new SybDriver());

con =DriverManager.getConnection("jdbc:sybase:Tds:192.168.0.1:4000/dbName","username", "password");

} catch (SQLException e) {

e.printStackTrace();

}

-


i config JDBC connector in visual administration :

DataSource name: sy_DS;

DataSource aliases:sy_ds;

Dirver name:sybase_driver(a name of i 'd registered a sybase jdbc1 driver );

JDBC version:1.X;

driver class:com.sybase.jdbc.SybDriver;

DataBase URL:jdbc:sybase:Tds:192.168.0.1:4001/dbName;

user: username

password:password

===============================

follow coder is in webdynpro implementation to obtain a connecton:

....

try {

Context ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup("jdbc/sy2_ds");

Connection c =ds.getConnection();

<b><u> /*

debug by step by step get a exeception here:

com.sap.engine.services.dbpool.exceptions.BaseSQLException: ResourceException in method ConnectionFactoryImpl.getConnection(): com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: com.sap.sql.log.OpenSQLException: Porting factory for ADAPTIVE SERVER ENTERPRISE database not defined.

*/</u></b>

} catch (NamingException e) {

e.printStackTrace();

}

-