ActionScript MySQL Driver?asSQL,access database from Flex

 

As we all know,we can not use that datasource to connect to a database with flex,and Flex does not connect to DB directly.There is better data integration with FlexBuilder 3 but we also can not connect to a database directly and load/push data,it’s in the form of wizards to help developers write server code side to talk to databases.Then from Flex how does flex appication access data from a database?

 

We can do it by HTTPService,WebService and RemoteObject,but not only it.The open source project named asSQL gives me a suprise! asSQL is an AcrtionScript 3 driver to connect to mySQL directly without having any middle tire scripts.This works by creating a socket connection directly from the user’s computer to a database exposed to the internet. The usersname and password are embedded in the .swf client to make the connection and perform queries. Although this project is still in an Alpha stage but this is a good attempt.You can find more information on the project, as well as download code and samples from here.This could be extremely useful for Apollo applications which won’t be able to use PHP locally to connect to a database.

Here is the steps to create access to database using Java.

Basically, there are three steps you need to accomplish in order to communicating with database from flex.
Step 1. Write java code to communicate to the database. We usually call this an Assembler. In here, you provide the information about what database and jdbc driver you are connecting to, and create a connection to it.

Step 2. Then config a destination which point to the Assembler in data-management.xml. Any flex app uses this destination will use this Assembler, and connecting to the same database.

Step 3. In your flex code, you reference the data service like this:
dsEmployee = new DataService(”crm.company”);
the crm.company is a destination defined in step 2.

Here is a simple sample source by asSQL.And you can try it by yourself.

Step 1?Create a MySQL database named myAsDb,and import the schema
Step 2?Download asSQL SWC from here
Step 3?New Flex Project,right click Properties ->Flex Build Path ->Library Path,click right button to add SWC,you can find the SWC that be downloaded at Step 2
Step 4?Edit Flex interface elements,add one ComboBox , one DataGrid and two Button,then edit MXML file.

The below is screenshot :