Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Handel ArrayList and HashMap (java util Pack) in Web Services

 
k Jayapradeep
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I am jayapradeep,

I create java class file which contain method public ArrayList getStockDetail(String cname,String symbol ) ,after that i create WSDL file for that class(Stock).In client side i can not received the return value.so i change the return type as String .
Can you explain for if any alternate for ArrayList, except String return type.

Example code:

public class Stock
{
public ArrayList getStockDetail(String cname,String symbol ) throws Exception
{

ArrayList theResultList = new ArrayList();
Connection aCon = null;
PreparedStatement aPS = null;
ResultSet aRS = null;
StringBuffer stockQuery = new StringBuffer( "" );

stockQuery.append( " SELECT " );
stockQuery.append( " CNAME, " );
stockQuery.append( " CSYSMBOL, " );
stockQuery.append( " MARKETTYPE, " );
stockQuery.append( " CADDRESS, ");
stockQuery.append( " QUOTES_LAST, ");
stockQuery.append( " QUOTES_WH, " );
stockQuery.append( " QUOTES_WL, " );
stockQuery.append( " QUOTES_MC ");
stockQuery.append( " FROM STOCK " );
stockQuery.append( " WHERE CNAME LIKE ? " );
stockQuery.append( " OR CSYSMBOL Like ? " );

System.out.println("---------------------");
System.out.println(stockQuery);
System.out.println("---------------------");

try
{
aCon = ConnectionConf.getConnection();
aPS = aCon.prepareStatement( stockQuery.toString() );


aPS.setString( 1, cname );
aPS.setString( 2, symbol.toUpperCase() );

HashMap htTemp = null;
for( aRS = aPS.executeQuery(); aRS.next(); theResultList.add(htTemp) )
{
htTemp = new HashMap();
htTemp.put( "CNAME" , aRS.getString( "CNAME" ) );
htTemp.put( "CSYSMBOL" , aRS.getString( "CSYSMBOL" ) );
htTemp.put( "MARKETTYPE" , aRS.getString( "MARKETTYPE" ) );
htTemp.put( "CADDRESS" , aRS.getString( "CADDRESS" ) );
htTemp.put( "QUOTES_LAST" , aRS.getString( "QUOTES_LAST" ) );
htTemp.put( "QUOTES_WH" , aRS.getString( "QUOTES_WH" ) );
htTemp.put( "QUOTES_WL" , aRS.getString( "QUOTES_WL" ) );
htTemp.put( "QUOTES_MC" , aRS.getString( "QUOTES_MC" ) );
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
aCon.close();
aRS.close();
}
return theResultList;
}

}
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use an array instead: http://www.ibm.com/developerworks/xml/library/ws-tip-coding.html

In the future, please UseCodeTags when posting code of any length. It's unnecessarily hard to read as it is, making it more likely that people will skip it altogether.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic