on 03-08-2011 9:28 AM
Hi Experts,
I have created a dictionary project with a database table TMP_TABLE1 with fields ID,NAME
How can we insert new records and read those records from web dynpro Perspective?I am not using Java beans and EJB
Regards,
Manivannan P
hi,
In web dynpro perspective,create web dynpro project with two i/p file bind with context id and name.create a button which bind with method m_insertRecord.
code for creation record
public java.lang.String m_insertRecord( )
{
Strin rslt=null;
try{
// Get the database connection
Context g_context=new InitialContext();;
DataSource g_ds=(DataSource) g_context.lookup("jdbc/TMP/TEST");
Connection g_connect=g_ds.getConnection();
PreparedStatement l_ps = null;
String Query="insert into TMP_TABLE1(ID, NAME )values (?,?)";
l_ps = g_connect.prepareStatement(lQuery);
l_ps.setSInt(1, wdContext.currentContextElement().getID());
l_ps.setString(2, wdContext.currentContextElement().getName());
int result = l_ps.executeUpdate();
if(result== 1)
{
return rslt="record save";
}
}
catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
return rslt;
create a button and bind with the method m_DisplayRecord
code for display the record
public void String m_DisplayRecord( )
{
Strin rslt=null;
try{
// Get the database connection
Context g_context=new InitialContext();;
DataSource g_ds=(DataSource) g_context.lookup("jdbc/TMP/TEST");
Connection g_connect=g_ds.getConnection();
PreparedStatement l_ps = null;
ResultSet l_rs = null;
String Query="SELECT * FROM TMP_TABLE1";
l_ps = g_connect.prepareStatement(lQuery);
l_rs = l_ps.executeQuery();
while (l_rs.next()) {
String name=l_rs.getString("NAME"),
int id=l_rs.getInt("ID")
}
}
catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
Edited by: Abhilasha Dahare on Mar 8, 2011 12:13 PM
Edited by: Abhilasha Dahare on Mar 8, 2011 12:21 PM
Edited by: Abhilasha Dahare on Mar 8, 2011 12:23 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
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.