开发者

Want to pull data from DATABASE using Java And Flex

I Am Completely novice in flex could you just let me know 开发者_Python百科about it plz.I want to access data from a database residing on a particular ip address and also i am not sure how to do it pl let me know how it can be done through flex framework.


Being a client side technology, it would be a real problem allowing direct access to the database. What you need is some server application to mediate the access to the database. This could be written in many different ways, but the majority of developers would use PHP/.net/Java


There are many ways to access your data. For simple stuff, you could use a servlet that will fetch data from db and provide it to the flex running on the client. instead of servlets, you could also use web services. On the flex side, you have three ways to access data: HTTPService, WebService, and RemoteObject. Its up to you to select one of them ( as I don't know what your requirements are and how well you know on these).


There are many different options. Check out a screencast I did on Flex and Java basics that walks through the various options.


Your Flex frontend
 <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" backgroundColor="#FFFFFF" viewSourceURL="srcview/index.html">

                <mx:RemoteObject id="myservice" fault="faultHandler(event)" 
        showBusyCursor="true" destionation="yourDest">
                    <mx:method name="JavaMethodName" result="resultHandler(event)" />
                </mx:RemoteObject>

                <mx:Script>
                    <![CDATA[
                        import mx.rpc.events.ResultEvent;
                        import mx.rpc.events.FaultEvent;
                        private function faultHandler(evt:FaultEvent):void
                        {
                           trace(evt.fault);
                        }

                        private function resultHandler(evt:ResultEvent):void
                        {
                            trace(evt.result);
                        }
                    ]]>
                </mx:Script>

                <mx:Button x="250" y="157" label="Click" width="79" click="myservice.getOperation('JavaMethodName').send();"/>
            </mx:Application>

Remoting-Config.XML

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" 
    class="flex.messaging.services.RemotingService">

    <adapters>
        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
    </adapters>
    <destination id="yourDest">  
        <properties>
            <source>YourClassName</source>  
        </properties>  
   </destination>  
    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>

</service>

Your Java Class

import java.util.Date;


public class YourClassName{

    public String JavaMethodName() {
        Date now = new Date();
        return "Yourname " + now;  
    }  
}

Now in your Java Class you need to write out your JDBC connection and call the database and which you can return to flex as an Object from there you can display it in frontend in what ever format.


Look at the documentation for Adobe BlazeDS. This will show you how to do what you want and how to implement for example what Vinothababu suggested. Here's the link: http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜