cancel
Showing results for 
Search instead for 
Did you mean: 

Using JDBC to connect to MS SQL DB from a J2EE Application

Former Member
0 Kudos

Hi,

I am trying to connect from my J2EE application to a MS SQL Server Database via JDBC.

I am not able to successfully connect, and am getting the following error:

"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"

The following code is used to get the connection:

InitialContext ctx = new InitialContext();

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

conn = ds.getConnection();

The exact same code is working fine within a Web DynPro project, so I don't think there is an issue with JDBC setup on the J2EE Web Server. Do you have any idea as to why I am unable to connect when using a J2EE Application instead?Am I missing something critical?

Thanks in advance,

Michael

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Have you specified the JNDI Name as follows in ejb-xml

<ejb-jar>

...

<enterprise-beans>

...

<entity>

...

<resource-ref>

<res-ref-name>jdbc/ejavaPool</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

</entity>

...

</enterprise-beans>

...

</ejb-jar>

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

I am not using an EJB project. I basically have an Enterprise Project as well as a Web Project.

Do I need to specify the data source inside a specific XML within my project. (I have already created a data source for JDBC Connector in Visual Admin)

Thanks,

Michael