[Air] 외부 MYSQL 접속 데이터 값 가져오기 Air



<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
   xmlns:s="library://ns.adobe.com/flex/spark" 
   xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="onCreationComplete()" width="640" height="470" currentState="login" width.login="640" height.login="470">
<fx:Script>
<![CDATA[
import com.maclema.mysql.Connection;
import com.maclema.mysql.MySqlToken;
import com.maclema.mysql.ResultSet;
import com.maclema.mysql.Statement;
import com.maclema.mysql.events.MySqlErrorEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.ListEvent;
import mx.rpc.AsyncResponder;
private var con:Connection;
private var st:Statement;
private var token:MySqlToken;
[Bindable]
private var dataAC:ArrayCollection;
private function onCreationComplete():void
{
con = new Connection("디비주소", 3306, "디비아이디", "디비비밀번호", "디비");
con.addEventListener(Event.CONNECT, handleConnected);
con.connect("utf8");
}
private function handleConnected(e:Event):void
{
if (con != null)
{
st = con.createStatement();
}
var token:MySqlToken = st.executeQuery("SELECT * FROM hospital_1");
token.addResponder(new AsyncResponder(selectResult, fault)); 
}
private function selectResult(data:Object, token:Object):void
{
var rs:ResultSet = ResultSet(data);
dataAC = rs.getRows();                                
}
private function insertResult(data:Object, token:Object):void
{
Alert.show(token.description + " 삽입성공!");
selectProcess();
//insertBox.visible = false;
}
private function fault(info:Object, token:Object):void
{
Alert.show("Error: " + info);    
}
private function selectProcess():void
{
   
}
private function insertProcess():void
{
st.sql = "INSERT INTO products (Name, Id) VALUES (, ?)";
// st.setString(1, inputDescription.text);
// st.setNumber(2, Number(inputPrice.text));
var token:MySqlToken = st.executeQuery();
// token.description = inputDescription.text;
token.addResponder(new AsyncResponder(insertResult, fault, token));
}

protected function memberInsert_clickHandler(event:MouseEvent):void
{
}


protected function productDG_itemClickHandler(event:ListEvent):void
{
memberInsert.label = productDG.selectedItem.Id;
}


protected function loginButton_clickHandler():void
{
// TODO Auto-generated method stub
currentState="stageMain";
}

]]>
</fx:Script>
<s:states>
<s:State name="stageMain"/>
<s:State name="login"/>
</s:states>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:ApplicationControlBar width="100%" dock="true" height="33" includeIn="stageMain">
<s:Button label="회원추가" id="memberInsert" click="memberInsert_clickHandler(event)"/>
</mx:ApplicationControlBar>
<mx:VBox horizontalAlign="center" x="4" width="100%" height="100%" top="50" includeIn="stageMain">
<mx:DataGrid id="productDG" dataProvider="{dataAC}" width="100%" height="100%" itemClick="productDG_itemClickHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="ID" dataField="Id"/>
<mx:DataGridColumn headerText="이름" dataField="Name"/>
<mx:DataGridColumn headerText="주소" dataField="Address"/>
<mx:DataGridColumn headerText="성별" dataField="Sex"/>
<mx:DataGridColumn headerText="전화번호" dataField="Phone"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
<mx:Panel includeIn="login" width="258" height="142" id="login_panel" title="관리자 모드 로그인" layout="absolute"  horizontalCenter="0" verticalCenter="0">
<mx:Form width="100%" height="100%" id="login_Form"  x="0" y="0" paddingLeft="10" paddingTop="10" paddingRight="0" paddingBottom="0">
<mx:FormItem label="아이디"  required="true" horizontalAlign="center">
<mx:TextInput id="adminId" text="hospital_1"/>
</mx:FormItem>
<mx:FormItem label="비밀번호"  required="true" horizontalAlign="center">
<mx:TextInput id="adminPw" displayAsPassword="true" enter="loginButton_clickHandler()" text="1"/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom="0" height="29" y="161"  horizontalAlign="right" verticalAlign="top" id="login_controlBar">
<s:Button id="loginButton" click="loginButton_clickHandler()" />
</mx:ControlBar>
</mx:Panel>
</s:WindowedApplication>


덧글

  • pokute 2011/01/20 10:45 # 삭제 답글

    flex3인지 4인지 미리 알려주셔야죠
댓글 입력 영역