Skip to Content
0
Former Member
Dec 04, 2006 at 01:45 PM

Need to connect to SQL Server Database from a JSP using JDBC Connector

153 Views

Hi I have my EP6 SP 16 Portal running on Oracle DB.

I want to connect to a remore SQL server 2005 DB from the WAS Java 6.40.

I have registered the JDBC driver (downloaded from microsoft for SQL Server 2005).

After Rigistering the driver i have created one data sourse (via Visual Admin).

Using that Data Sourse (DB Initialization TAB in visual admin ) I am able to successfully conenct to the remote SQL server DB and able to execute sql statements and getting the output.

Now I want to make use of this Datasourse from within an JSP page.

I have written one jsp page with the following code .

try

{

Connection con;

Context ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup("jdbc/<MY DS Name>");

con = ds.getConnection();

out.println("Database connection sucessfull.");

}

catch(Exception e)

{

out.println("<center><font color='red'>Jdbc Installation Failed!</font></center>");

out.println(e);

}

%>

This test.jsp (say) has been placed withing the folder

...usr\sap\APQ\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root

But I am not able to get the connection .

Can any one help me providing the code to get this done .