前幾天有網友要我寫一篇關於flex與數據庫交互的例子
對於建立一個flex web應用的步驟我就不多說了哈
首先要求大家到數據庫建立一個數據庫
User
package org
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name){
this
}
}
UserDao
package org
import java
import java
import java
import java
import java
import java
import java
public class UserDao {
public static Connection getConnection(){
Connection c=null;
try{
String driver=
String url=
String username=
String password=
Class
c=DriverManager
}catch(Exception e){
System
}
return c;
}
public List getAllUser()throws SQLException{
Connection c=getConnection();
Statement st=c
ResultSet rs=st
ArrayList userList=new ArrayList<User>();
while(rs
User u=new User();
u
userList
}
return userList;
}
}
以上是java端的全部代碼了
第三
User
package org
{
[RemoteClass(alias=
public class User
{
private var _name:String;
public function User()
{
}
public function get name():String{
return this
}
public function set name(name:String):void{
this
}
}
}
User
package org
{
[RemoteClass(alias=
public class User
{
private var _name:String;
public function User()
{
}
public function get name():String{
return this
}
public function set name(name:String):void{
this
}
}
}
接下來是mxml代碼
FlexWithJava
<?xml version=
<mx:Application xmlns:mx=
<mx:RemoteObject id=
<mx:DataGrid dataProvider=
<mx:columns>
<mx:DataGridColumn dataField=
</mx:columns>
</mx:DataGrid>
<mx:Label id=
<mx:Button label=
<mx:Script>
<![CDATA[
import llections
import mx
[Bindable]
public var users:ArrayCollection=new ArrayCollection();
public function clickFun():void{
ud
}
public function onResult(event:ResultEvent):void{
users=ArrayCollection(event
info
}
public function onFault():void{
info
}
]]>
</mx:Script>
</mx:Application>
第四
<destination id=
<properties>
<source>org
</properties>
</destination>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19263.html