cancel
Showing results for 
Search instead for 
Did you mean: 

webdynpro application to the sql server

Former Member
0 Kudos

Hi,,

iam trying to connect web dynpro application to an SQL server.Iam using two labels with name and email

and two buttons like insert and submit.Please provide the code for this in webdynpro to connect to the SQL server.

Regards

Sushma

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi sushma,

Refer

/people/anilkumar.vippagunta2/blog/2007/02/20/reading-and-writing-images-from-sqlserver-in-webdynpro

Regards,

P.Manivannan

Answers (8)

Answers (8)

Former Member
0 Kudos

thanks

Former Member
0 Kudos

Sushma,

For connecting to SQL Server, you should configure a data source in Visual Administrator and use this Datasource in WebDynpro to connect to backend database system.

You can find steps in the link below:

/people/william.li/blog/2007/03/30/using-jdbc-connection-pool-in-xi-message-mapping

vinod

Former Member
0 Kudos

hi ,

i have follow the following method to connect to sql from webdynpro...

1. created a dsn in VA

i have created a one java class under util folder under src...in webdynpro

and put this code in that class..

package com.satyam.util;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.Vector;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import javax.sql.DataSource;

/**

  • @author QH39644

*

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

public class DB_Connect {

private Connection conn;

private DataSource ds = null;

private int ColCount=0;

// public Connection getConnection(String DSN)

// {

//

// conn = get

//

// return conn;

// }

private DataSource getDataSource(String strDsName) throws Exception {

String datasourceJNDI = null;

String datasourceType = null;

if (ds == null)

datasourceJNDI = strDsName;

ds = (DataSource) getJNDIContext().lookup(datasourceJNDI);

return ds;

}

public Connection getConnection(String strDsName) throws Exception {

try {

if (conn == null || conn.isClosed()) {

conn = getDataSource(strDsName).getConnection();

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return conn;

}

private Context getJNDIContext() throws Exception {

Context ctx = null;

try {

ctx = new InitialContext();

} catch (NamingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return ctx;

}

after just call this metohd when u want to get a connection..

code for that is as follow...DB_connect is java class name that i have created..

ARGNewUser is a DSn name that i have created in VA.

DB_Connect getConnection = new DB_Connect();

Connection Conn = null;

try {

Conn = getConnection.getConnection("jdbc/ARGNewUser");

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Former Member
0 Kudos

Hi,

go through the links.

Regards,

Srikanth Reddy.T

Former Member
0 Kudos

Hi,

Try this code

Connection conn=null;

try

{

String userName = "jktuser";

String password = "jkt12345";

String url ="jdbc:sqlserver://jktr3:50000;database=student";

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());

conn =DriverManager.getConnection(url, userName, password);

Statement stmt=conn.createStatement();

ResultSet rs=stmt.executeQuery("select * from studentdata"); // select statment

while(rs.next())

{

......

}

}catch(Exception ex)

{

wdComponentAPI.getMessageManager().reportException(ex.getLocalizedMessage(),true);

}

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Hi sushma,

please check the link below. it will be very useful to you.

Regards

Narendra

Former Member
0 Kudos

Hi

Thanks,

Tulasi

Edited by: Tulasi Palnati on Jan 9, 2009 3:45 AM

Former Member
0 Kudos

Hi Sushma,

You have to either use EJB for more complexity or if you want to directly connect from webDynpro then you can use JDBC code directly.

bellow is the sample JDBC code where you have to replace the variables in sign <> with the appropriate details.

String url ="jdbc:microsoft:sqlserver://<Server URL>;databaseName=<DBName>";

String querry="<SQL Query>";

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver";);

Connection con =DriverManager.getConnection(url, <UserName>, <Password>);

Statement st=con.createStatement();

Ninad