Avatar

Level 2















Hi mydears of this world

Here i come along with my problem with the hope that some
one can resolve it

i am totally new to flex and i am working only for the past
3 days in flex. and i learned a little bit.

i want to get the database values which is received from
java object to flex datagrid with the help of data provider.

i did it pretty well according to me. But i could not
produce the result in the data grid . since i am very new . i dont
know what is happening.



my code is here , please help me.



My mxml file : Myadmin.mxml



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="vertical">

<mx:RemoteObject id="ber" destination="berth"
showBusyCursor="true" fault="faultHandler(event)" >

<mx:method name="getBerth"
result="resultHandler(event)"/>

</mx:RemoteObject>



<mx:Panel id="topPanel" title="MyDatabase" width="100%"
height="40%" enabled="true">

<mx:TextArea id="sql" width="100%" height="100%"/>



<mx:Button label="Execute" click="handleSend()"/>



</mx:Panel>



<mx:Panel id="bottomPanel" title="Results" width="100%"
height="60%" enabled="true">

<mx:DataGrid id="dg" dataProvider="{result}" width="100%"
height="100%"/>





</mx:Panel>

<mx:Label id="resultLabel" text ="Onumae puriyale
ulgathulae" />



<mx:Script>

<![CDATA[



import mx.rpc.events.*;

import mx.collections.*;

import mx.controls.*;

import mx.utils.ObjectUtil;









//cached empty ArrayCollection so that we don't keep
creating

//new ones



private var emptyResults:ArrayCollection = new
ArrayCollection();



[Bindable]

public var result:ArrayCollection = emptyResults;















private function resultHandler(event:ResultEvent):void

{

Alert.show("event.result array results",
ObjectUtil.toString(event.result as ArrayCollection));

result = ArrayCollection(event.result);

var myCursor:IViewCursor=result.createCursor();

var oldLength:int=result.length;



Alert.show(oldLength.toString());









}



private function faultHandler(event:FaultEvent):void

{

Alert.show(event.fault.faultString, "Error");

}



private function handleSend():void

{





ber.getBerth();





}









]]>

</mx:Script>





</mx:Application>



My java Object : Berth.java





package samples.sqladmin;

import java.sql.*;

import java.util.*;

import java.io.*;



public class Berth



{

public static void main(String args[])throws Exception

{

ArrayList list = getBerth();

System.out.println("The List is =" + list);

}



public static ArrayList getBerth()throws Exception {

Connection con = null;

Statement st = null;

ResultSet rs = null;

ResultSetMetaData rsmd = null;

ArrayList list = new ArrayList();

HashMap row=null;

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}catch(ClassNotFoundException cnfe){

System.out.println(cnfe.getMessage());

}

try{

con = DriverManager.getConnection("jdbc:odbc:Jurong","","");

st = con.createStatement();

String sql = "select * from berth ";

rs=st.executeQuery(sql);

rsmd = rs.getMetaData();

int colCount = rsmd.getColumnCount();

while (rs.next()) {

row=new HashMap();

for (int i = 1; i <= colCount; i++) {

row.put(rsmd.getColumnName(i), rs.getString(i));

}

list.add(row);

}



}

catch(SQLException sqle){

System.out.println("enna da yogans eeeeee....");

System.out.println(sqle.getMessage());

}



if(con != null)

con.close();

if(st != null)

st.close();

return list;



}



}



my remote-config file is:



<destination id="berth">

<properties>

<source>samples.sqladmin.Berth</source>

</properties>

</destination>



i got the array collection object in flex but it is not
giving the values which received in java



please help me .

Thanks in advance

yogans.