cancel
Showing results for 
Search instead for 
Did you mean: 

Java Dictionary

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

closed

Answers (0)