日期:2014-05-16  浏览次数:20715 次

Flex 使用assql 连接mySQl数据库

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
????? xmlns:s="library://ns.adobe.com/flex/spark"
????? xmlns:mx="library://ns.adobe.com/flex/mx"
????? xmlns:assql="com.maclema.mysql.mxml.*"
????? minWidth="955" minHeight="600">
?<s:layout>
??<s:BasicLayout/>
?</s:layout>
?<fx:Declarations>
??<!-- 将非可视元素(例如服务、值对象)放在此处 -->
??<assql:MySqlService id="service"
???????hostname="localhost"
???????username="root"
???????password="root"
???????database="jpetstore"
???????autoConnect="true"
???????port="3306"
???????connect="handleConnected(event)"
???????sqlError="handleError(event)" />
?</fx:Declarations>
?
?
?<fx:Script>
??<![CDATA[
???import mx.controls.Alert;
???import com.maclema.mysql.events.MySqlErrorEvent;
???import com.maclema.util.ResultsUtil;
???
???private function handleConnected(e:Event):void {
????Alert.show("连接成功")
????service.send("SELECT * FROM user");
???}
???
???private function handleError(e:MySqlErrorEvent):void {
????Alert.show(e.text);
???}
??]]>
?</fx:Script>
?<!--Flex ActionScript3.0 MySql 数据驱动连接Demo-->
?<mx:DataGrid id="grid" left="10" right="10" top="10" bottom="10"
???? dataProvider="{service.lastResult}"
???? columns="{ResultsUtil.getDataGridColumns(service.lastResultSet)}" />
?
</s:Application>