Flex to write data to the database

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

In this paper, through method calls to the remote object to operate the database, how to set up BlazeDS, I will not say more,

There are many articles about BlazeDS online, Baidu Search can.

----------------------------------------------------------------------------------------------------------------------------

Flex database to write data general steps:

The 1 definition database table.

2 preparation and database table corresponding to the Java class VO (Java class bean?).

3 write data insertion method.

4 definition of the flex VO class, the class corresponding to the Java class Vo.

5.flex remote method invocation.

-------------------------------------------------------------------------------------------------

Look at the table (3 column):


--------------------------------------------------------------------------------------------------------------------------------------

The Java VO class.:

package bean;

public class Admin { //The corresponding database table tbAdmin
	int id;
	String usrName;
	String usrPass;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUsrName() {
		return usrName;
	}
	public void setUsrName(String usrName) {
		this.usrName = usrName;
	}
	public String getUsrPass() {
		return usrPass;
	}
	public void setUsrPass(String usrPass) {
		this.usrPass = usrPass;
	}
}

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The server data insertion method:

@Override
	public int AddAdmin(Admin admin) { //Add the administrator

				String sql="insert into tbAdmin(id,usrName,usrPass)" +
						" values (0?,'1?','2?')";
				sql=sql.replace("0?",String.valueOf(admin.getId()));
				sql=sql.replace("1?",admin.getUsrName());
				sql=sql.replace("2?",admin.getUsrPass());
				System.out.println(sql);
				return DbCRUD.Add(sql);
	}

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The configuration remoting-config.xml file:

<?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>

    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>

	<destination id="adminDAOImpl">  
        <properties>  
            <source>dao.impl.AdminDAOImpl</source>  
        </properties>  
	</destination>  
</service>


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The flex VO class (note to server-side java and VO correspondingly):

package vo
{
	[RemoteClass(alias="bean.Admin")] //This sentence can not be less
	public class Admin
	{
		public var id:int;  
		public var usrName:String;  
		public var usrPass:String;  
		
		public function Admin()//Constructor
		{
			
		}
	}
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Add data flex remote call server:

The 1 statement of the remote object:

<fx:Declarations>
<!-- non visual elements (such as service, value object) here -->
<s:RemoteObject id="roAdmin" destination="adminDAOImpl">
<s:method name="GetAllAdmin" result="rstGetAllAdmin(event)" fault="fltGetAllAdmin(event)"/>
<s:method name="AddAdmin" result="rstAddAdmin(event)" fault="fltAddAdmin(event)"/>
</s:RemoteObject>
</fx:Declarations>

2 remote method invocation:

                        //Add user
			import vo.Admin;//To import the package
			protected function btnAdd_clickHandler(event:MouseEvent):void
			{
				//Create object
				 var admin:Admin=new Admin();
				admin.id=int(txbId.text);
				admin.usrName=txbUsrName.text;
				admin.usrPass=txbUsrPass.text;  
				
				roAdmin.AddAdmin(admin);//Calls to the remote object
			}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Screenshots:



---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Your satisfaction is my pursuit of purpose.

A bit of advice you is my motivation for subsequent.







Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Roy at January 03, 2014 - 4:32 AM