this code can be work,it is write of me:
package lib.tools
{
import flash.utils.ByteArray;
public class getConn
{
import flash.data.SQLConnection;
import flash.data.SQLStatement;
import flash.data.SQLResult;
import flash.data.SQLMode;
import flash.events.SQLErrorEvent;
import flash.events.SQLEvent;
import flash.filesystem.File;
import mx.core.UIComponent;
import flash.data.SQLConnection;
public var Conn:SQLConnection;
/* 定义连接函数
wirten by vivid msn:[email protected] */
public function getConn(database:Array)
{
Conn=new SQLConnection();
var Key:ByteArray=new ByteArray(); ;
Key.writeUTFBytes("Some16ByteString");
Conn.addEventListener(SQLErrorEvent.ERROR, createError);
var dbFile:File =File.applicationDirectory.resolvePath(database[0]);
Conn.open(dbFile);
if(database.length>1){
for(var i:Number=1;i<database.length;i++){
var DBname:String=database[i]
Conn.attach(DBname.split("\.")[0],File.applicationDirectory.resolvePath(DBname));
}
}
/* 加密码的选项
wirten by vivid msn:[email protected] */
Conn.open(dbFile, SQLMode.CREATE, false, 1024, Key);
}
/* 出错返回信息函数
wirten by vivid msn:[email protected] */
private function createError(event:SQLErrorEvent):void
{
trace("Error code:", event.error.details);
trace("Details:", event.error.message);
}
/* 定义执行sql函数
wirten by vivid msn:[email protected] */
public function Rs(sql:Array):Object{
var stmt:SQLStatement = new SQLStatement();
Conn.begin();
stmt.sqlConnection = Conn;
try{
for(var i:String in sql){
stmt.text = sql[i];
stmt.execute();
}
Conn.commit();
}catch (error:SQLErrorEvent){
createError(error);
Conn.rollback();
};
var result:Object =stmt.getResult();
return result;
}
}
}