DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Connecting To SQLite

Jonnie Spratley user avatar by
Jonnie Spratley
·
Sep. 21, 08 · · Code Snippet
Like (0)
Save
Tweet
2.15K Views

Join the DZone community and get the full member experience.

Join For Free
For connecting to and creating a db, use the code as follows:


//DB Connection
private var dbconn:SQLConnection;
//Query Statement
private var sqlQuery:SQLStatement;		
//Create Table Statement
private var sqlCreateTable:SQLStatement;
//Insert Statement
private var sqlInsert:SQLStatement;
//Import Statement
private var sqlImport:SQLStatement;

//Returned Data
[Bindable] private var sqlData:ArrayCollection;

/**
 * Creates a database connection, registers event listeners, specifies the database filename
 * checks to see if the database exsists, if it does then we connection to it.
 * If it doesnt, then we create a new database file, and create our tables.
 * 
 * @constructor
 */		
public function DatabaseManager()
{
	//Connect to the db
	dbconn = new SQLConnection();
		
	//Add event listener
	dbconn.addEventListener( SQLErrorEvent.ERROR, onSQLError );
	
	//Set the location of the db file				
	var dbFile:File = File.applicationStorageDirectory.resolvePath( "MyDatabase.db" );
	
	//Check if the db file exsists
	if ( dbFile.exists )
	{
		//Connect to the db then
		dbconn.addEventListener( SQLEvent.OPEN, onSQLOpen );
	} else {
		//Create the db
		dbconn.addEventListener( SQLEvent.OPEN, onSQLCreate );	
	}
	//Execute
	dbconn.openAsync( dbFile );			
}	

SQLite

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Modern REST API Design Principles and Rules
  • Memory Debugging and Watch Annotations
  • What SREs Can Learn From the Atlassian Nightmare Outage of 2022
  • How to Leverage Method Chaining To Add Smart Message Routing in Java

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo