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 :

Campfire

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

10 Responses to “ActionScript MySQL Driver:asSQL,access database from Flex”

  1. Abdul Qabiz says:

    It’s indeed good proof-of-concept work and can be made more usable/secure. However, I feel it’s not good idea to keep database credentials (login details) in client-side app. Any SWF decompiler, whenever it’s available, can show such details.

    If someone is going to use assql, make sure you pass authentication credentials on runtime to client and probably by encrypting/hashing in some form so that HTTP spoofing doesn’t reveal the information. There are couple of ways:-

    1) Use URLStream to load some bytes on runtime
    2) Pass those information over another socket connection in form of bytes..

    None of these methods are bullet-proof, but you can make things harder if not impossible to crack.

    -abdul

  2. Mike Britton says:

    I agree with Abdul’s assertion that secure information never be present in a client side app. While this is a compelling exercise, I’m also unsure of the benefits of excluding a middle tier. A properly designed middle tier allows access for any app. Most large middle tiers I’ve worked with are XML RPC or SOAP for a reason. Nice work though, seriously. I can envision an AS front-to-back solution, and despite our reliance on middle tiers as a reality inherent in working with backend developers and DBAs, someday this will become a compelling option for enterprise apps.

  3. Vini says:

    Hello, I really like your code. Can you update it to work with the latest SWC library? Hope you get this.

  4. sandeep says:

    What is this scrambler????

  5. Avinash says:

    Hi…is it possible to have this calling of database thing in an external AS file which again calls the Java Wrapper? In this way we can just include/call this particular AS file(in a different project) and not have the credentials embedded in the AS file. We just get the data. Does that make sense?

  6. Hi…is it possible to have this calling of database thing in an external AS file which again calls the Java Wrapper? In this way we can just include/call this particular AS file(in a different project) and not have the credentials embedded in the AS file. We just get the fies and will have acess the database from different computers + flex

  7. Henry says:

    I downloaded the Alpha version (asSQL-0.1alpha.swc), the Beta version (asSQL2[1].7.swc) and the zip file (asSQL2[1].7-FlexLibraryProject.zip which has a assql.swc include). I’m using FlexBuilder 3 and followed your example to find my project name, right click Properties ->Flex Build Path ->Library Path, then clicked right button to add SWC. After clicking Ok I get the following warning: Design mode: Cannot load assql.swc (reason: ERROR: Load Verify). It may require classes (such as Adobe AIR components) that are not supported by design mode. Check the Eclipse error log for more details. Questions:
    1. While this is a warning and I’m in design mode will this cause me any issues later on?
    2. Which one of these versions should I really use? I think I should go with the Beta version but which one? the one that came in the zip file or the one I downloaded?

    Thanks

  8. Bill says:

    How do we connect the flex with mySql as there is no config.xml file.

    Step 1:Create a MySQL database named myAsDb,and import the schema.

    where do we direct the schema in the flex application to connect to mysql???

    thanks
    Bill

  9. Andres says:

    I’m sorry to bug, but where can I find the db schema, i have not found this examples nor the employees table info in the http://code.google.com/p/assql/

    Thanks.

  10. Johan says:

    is this safe? embedding username & pass in a client side swf? crack the swf and you got the key..

Leave a Reply