cancel
Showing results for 
Search instead for 
Did you mean: 

Connect to SAP database using Java?

Former Member
0 Kudos
511

Hello All,

My requirement is to connect to a SAP database using the Java Application. As per the information i have, We can create a Data dictionary using the SAP Netweaver. Accordingly i have created a data dictionary and deployed the sda file on the portal. Now i need to connect to that database using java jndi.

my database connection class has the foll code:

InitialContext ctx = new InitialContext();

DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/TMP_MEGHANA");

con = dataSource.getConnection();

I get the error: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

I am not sure where exactly do i have to specfy TMP_MEGHANA to be considered as a datasource.

Could some1 let me know how do i go about this problem?

Thanks in advance,

Meghana

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Check this code.

InitialContext ctx = new InitialContext();

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

Connection conn = ds.getConnection();

Use this connection now to create statement.

Regards,

Harini S

0 Kudos

Hi,

Check this:

Also check my replies in this thread:

Regards,

Praveen Gudapati