cancel
Showing results for 
Search instead for 
Did you mean: 

inserting and displaying records of dictionary table

Former Member
0 Kudos

hi all,

i hv created a dict table and deployed it..

nw in my web dynpro proj i am inserting records into it


try {
InitialContext initialContext = new InitialContext();
DataSource dataSource =(DataSource) initialContext.lookup("jdbc/SAP" + (String) System.getProperties().get("SAPSYSTEMNAME")+"DB");
java.sql.Connection connection = dataSource.getConnection();
		
PreparedStatement stmt = connection.prepareStatement("INSERT into DEMO_TABLE"
 +"(TITLE,DESCRIPTION,STATUS)"		
+ " values(?,?,?)");
try
{
stmt.setString(1,"TITLE1");
stmt.setString(2,"DESC1");
stmt.setString(3,"STATUS1");
stmt.addBatch();

stmt.setString(1,"TITLE2");
stmt.setString(2,"DESC2");
stmt.setString(3,"STATUS2");
stmt.addBatch();				
			
stmt.executeBatch();
}
finally
{
stmt.close();
}
			
connection.close();
	
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

i m trying to retrieve records by jst specifying the name of the table...


IWDMessageManager messageMgr = wdComponentAPI.getMessageManager();
	wdContext.nodeResultSet().invalidate();
	wdContext.nodeResultSetMetaData().invalidate();
	
	//	find if ResultSet has dynamic attribtues
 	boolean hasAttr = false;
 	for (Iterator iter = wdContext.nodeResultSet().getNodeInfo().iterateAttributes(); iter.hasNext();) 
 	{
 		hasAttr= true;
	 	break;
 	}
 	
	//	if ResultSet has some dynamic attributes, remove them first
	if(hasAttr == true)
	{
		wdContext.nodeResultSet().getContext().reset();
	}
	
	//	Get the database connection
 	
 	PreparedStatement stmt;
	Connection conn;
	try {
		InitialContext dbInitContext = new InitialContext();
		
		 Properties sysProperties = System.getProperties();
		
		 String sysname = sysProperties.getProperty("SAPSYSTEMNAME");
		 String dbName = "jdbc/" + "SAP" + sysname + "DB";
		
		 DataSource dataSource = (DataSource) dbInitContext.lookup(dbName);
		 conn = dataSource.getConnection();
		
		 String tableName = wdContext.currentContextElement().getTableName();
		 String SelectStmt = "Select * from" .concat(" " + tableName);
		
		//	Prepare the SQL statements
		 stmt = conn.prepareStatement(SelectStmt);
		
		//	Execute the Query
		 ResultSet resultSet = stmt.executeQuery();
		
		//	Get the result set metadata
		 ResultSetMetaData resultMetaData = resultSet.getMetaData();
		
		//	resultMetaData contains DB Column details
		 int numColumns = resultMetaData.getColumnCount();
		
		//	Create an element of ResultSetMetadata for every table column (attribute)
		//	Create a dynamic attribute for the context of ResultSet Node for every table column
		 String[] attributes = new String[numColumns];
		
		 for (int columnIndex = 1; columnIndex <= numColumns; columnIndex++) 
		 {
			 IResultSetMetaDataElement element = wdContext.nodeResultSetMetaData().createResultSetMetaDataElement();
			 String columnName = resultMetaData.getColumnName(columnIndex);
			 String columnType = resultMetaData.getColumnTypeName(columnIndex);
			 element.setColumnName(columnName);
			 attributes[columnIndex-1] = columnName;
			 element.setColumnType(columnType);
		
			//Adding dynamic attribtue to ResultSet Node
			wdContext.nodeResultSet().getNodeInfo().addAttribute(columnName,"java.lang.String");
			wdContext.nodeResultSetMetaData().addElement(element);
		}
		
		// Loop through every record of DB Table and create an element in ResultSet Node
			while(resultSet.next())
			{
				IResultSetElement element = wdContext.nodeResultSet().createResultSetElement();
		
				for (int recordIndex = 0; recordIndex < attributes.length; recordIndex++) 
				{
					// If the Object is null, make it as empty
					if(resultSet.getObject(attributes[recordIndex]) != null)
						{
							element.setAttributeValue(attributes[recordIndex],resultSet.getObject(attributes[recordIndex]).toString());
						}
				    else
					{
						element.setAttributeValue(attributes[recordIndex],"");
					}
				}
				wdContext.nodeResultSet().addElement(element);
			}
		stmt.close();
		conn.close();		

i get a blank table and the following error when i click show records btn:

Object not found in lookup of SAPPD1DB.

plz help

thanks and regards,

ankita

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos
PradeepBondla
Active Contributor
0 Kudos

Hi,

A simple thought....

remove wdContext.nodeResultSet().invalidate();

wdContext.nodeResultSetMetaData().invalidate(); from present place and put at the end of the code.

PradeeP

Former Member
0 Kudos

i did it....

its still the same........

Former Member
0 Kudos

Hi,

Please try to throw the exceptions from the excecption handlers and post the stack trace.

It seems to be an issue with the connection.

Regards

Ayyapparaj

Former Member
0 Kudos

its still the same..........