on 01-08-2009 11:38 AM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.