1 Reply Latest reply on Jan 29, 2011 7:51 PM by commadelimited

    Adobe Air Database Connection

    Daniel Gerep Level 1

      Hi fellas,



      I'm new to Adobe Air and I have looked around and couldn't find a decent tutorial about Air and Databases.


      I'm a web developer and I'm used to work with MySQL, is it possible to work with MySQL and Ar?


      I have found a piece of code on documentation but its not working and the debug is not returning any errors.


      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                     import flash.data.SQLConnection; 
                     import flash.data.SQLMode; 
                     import flash.events.SQLErrorEvent; 
                     import flash.events.SQLEvent; 
                     import flash.filesystem.File; 
                     private function init():void 
                          var conn:SQLConnection = new SQLConnection(); 
                          conn.addEventListener(SQLEvent.OPEN, openHandler); 
                          conn.addEventListener(SQLErrorEvent.ERROR, errorHandler); 
                          // The database file is in the application storage directory 
                          var folder:File = File.applicationStorageDirectory; 
                          var dbFile:File = folder.resolvePath("DBSample.db"); 
                          conn.openAsync(dbFile, SQLMode.UPDATE); 
                     private function openHandler(event:SQLEvent):void 
                          trace("the database opened successfully"); 
                     private function errorHandler(event:SQLErrorEvent):void 
                          trace("Error message:", event.error.message); 
                          trace("Details:", event.error.details); 
                <!-- Place non-visual elements (e.g., services, value objects) here -->
           <s:Label x="147" y="51" id="mensagem"/>


      I checked the directory said in the tutorial and did not found the .db file.


      Thanks in advance for any help.

        • 1. Re: Adobe Air Database Connection
          commadelimited Level 2

          Howdy Daniel...


          Sorry, but AIR cannot talk directly to MySQL. I think however that you'll find that SQLite is quite a decent substitute. Let's take a look at your code.


          When you run this in debug, which EventListener fires? One of them has to be firing.


          Unless you've put the SQLite file in the AppStorageDirectory yourself, your code will not run. This code you've got only opens, it does not also create.


          I'd recommend working with SQLite files using a tool called Lita. It's written in Flex and AIR and it's quite nice...plus it's free:




          Start by making sure the file lives where it's supposed to, and go from there.