Saving data in database using textbox and save button

Hello. I just want a help about my code because when i close the application the data that i add is not been saved.
Here is my code of save:
function saveData(event:MouseEvent):void
  status.text = "Saving data";
  insertStmt = new SQLStatement();
  insertStmt.sqlConnection = conn;
  var sql:String = "INSERT INTO employees (firstName, lastName, salary) VALUES (:param, :param1, :param2)";
  insertStmt.text = sql;
  insertStmt.parameters[":param"] = firstName.text;
  insertStmt.parameters[":param1"] = lastName.text;
  insertStmt.parameters[":param2"] = salary.text;
  insertStmt.addEventListener(SQLEvent.RESULT, insertResult);
  insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);
  insertStmt.execute();
Here is the full code:
import fl.data.DataProvider;
import flash.data.SQLResult;
import flash.data.SQLConnection;
import flash.filesystem.File;
import flash.data.SQLStatement;
import flash.data.SQLConnection;
var conn:SQLConnection;
var createStmt:SQLStatement;
var insertStmt:SQLStatement;
var insertStmt2:SQLStatement;
var insertStmt3:SQLStatement;
var selectStmt:SQLStatement;
var insert1Complete:Boolean = false;
var insert2Complete:Boolean = false;
saveBtn.addEventListener(MouseEvent.CLICK, saveData);
loadBtn.addEventListener(MouseEvent.CLICK, getData);
init();
function init():void
  conn = new SQLConnection();
  conn.addEventListener(SQLEvent.OPEN, openSuccess);
  conn.addEventListener(SQLErrorEvent.ERROR, openFailure);
  status.text = "Creating and opening database";
  // Use these two lines for an on-disk database
  // but be aware that the second time you run the app you'll get errors from
  // creating duplicate records.
// var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");
// conn.openAsync(dbFile);
  // Use this line for an in-memory database
  conn.openAsync(null);
function openSuccess(event:SQLEvent):void
  conn.removeEventListener(SQLEvent.OPEN, openSuccess);
  conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);
  createTable();
function openFailure(event:SQLErrorEvent):void
  conn.removeEventListener(SQLEvent.OPEN, openSuccess);
  conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);
  status.text = "Error opening database";
  trace("event.error.message:", event.error.message);
  trace("event.error.details:", event.error.details);
function createTable():void
  status.text = "Creating table";
  createStmt = new SQLStatement();
  createStmt.sqlConnection = conn;
  var sql:String = "";
  sql += "CREATE TABLE IF NOT EXISTS employees (";
  sql += " empId INTEGER PRIMARY KEY AUTOINCREMENT,";
  sql += " firstName TEXT,";
  sql += " lastName TEXT,";
  sql += " salary NUMERIC CHECK (salary >= 0) DEFAULT 0";
  sql += ")";
  createStmt.text = sql;
  createStmt.addEventListener(SQLEvent.RESULT, createResult);
  createStmt.addEventListener(SQLErrorEvent.ERROR, createError);
  createStmt.execute();
function createResult(event:SQLEvent):void
  createStmt.removeEventListener(SQLEvent.RESULT, createResult);
  createStmt.removeEventListener(SQLErrorEvent.ERROR, createError);
  addData();
function createError(event:SQLErrorEvent):void
  status.text = "Error creating table";
  createStmt.removeEventListener(SQLEvent.RESULT, createResult);
  createStmt.removeEventListener(SQLErrorEvent.ERROR, createError);
  trace("CREATE TABLE error:", event.error);
  trace("event.error.message:", event.error.message);
  trace("event.error.details:", event.error.details);
function addData():void
  status.text = "Adding data to table";
  insertStmt = new SQLStatement();
  insertStmt.sqlConnection = conn;
  var sql:String = "";
  sql += "INSERT INTO employees (firstName, lastName, salary) ";
  sql += "VALUES ('Bob', 'Smith', 8000)";
  insertStmt.text = sql;
  insertStmt.addEventListener(SQLEvent.RESULT, insertResult);
  insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);
  insertStmt.execute();
  insertStmt2 = new SQLStatement();
  insertStmt2.sqlConnection = conn;
  var sql2:String = "";
  sql2 += "INSERT INTO employees (firstName, lastName, salary) ";
  sql2 += "VALUES ('John', 'Jones', 8200)";
  insertStmt2.text = sql2;
  insertStmt2.addEventListener(SQLEvent.RESULT, insertResult);
  insertStmt2.addEventListener(SQLErrorEvent.ERROR, insertError);
  insertStmt2.execute();
function insertResult(event:SQLEvent):void
  var stmt:SQLStatement = event.target as SQLStatement;
  stmt.removeEventListener(SQLEvent.RESULT, insertResult);
  stmt.removeEventListener(SQLErrorEvent.ERROR, insertError);
  if (stmt == insertStmt)
  insert1Complete = true;
  else
  insert2Complete = true;
  if (insert1Complete && insert2Complete)
  status.text = "Ready to load data";
function insertError(event:SQLErrorEvent):void
  status.text = "Error inserting data";
  insertStmt.removeEventListener(SQLEvent.RESULT, insertResult);
  insertStmt.removeEventListener(SQLErrorEvent.ERROR, insertError);
  trace("INSERT error:", event.error);
  trace("event.error.message:", event.error.message);
  trace("event.error.details:", event.error.details);
function getData(event:MouseEvent):void
  status.text = "Loading data";
  selectStmt = new SQLStatement();
  selectStmt.sqlConnection = conn;
  var sql:String = "SELECT empId, firstName, lastName, salary FROM employees";
  selectStmt.text = sql;
  selectStmt.addEventListener(SQLEvent.RESULT, selectResult);
  selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError);
  selectStmt.execute();
function saveData(event:MouseEvent):void
  status.text = "Saving data";
  insertStmt = new SQLStatement();
  insertStmt.sqlConnection = conn;
  var sql:String = "INSERT INTO employees (firstName, lastName, salary) VALUES (:param, :param1, :param2)";
  insertStmt.text = sql;
  insertStmt.parameters[":param"] = firstName.text;
  insertStmt.parameters[":param1"] = lastName.text;
  insertStmt.parameters[":param2"] = salary.text;
  insertStmt.addEventListener(SQLEvent.RESULT, insertResult);
  insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);
  insertStmt.execute();
function selectResult(event:SQLEvent):void
  status.text = "Data loaded";
  selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);
  selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);
  var result:SQLResult = selectStmt.getResult();
  resultsGrid.dataProvider = new DataProvider(result.data);
// var numRows:int = result.data.length;
// for (var i:int = 0; i < numRows; i++)
// var output:String = "";
// for (var prop:String in result.data[i])
// output += prop + ": " + result.data[i][prop] + "; ";
// trace("row[" + i.toString() + "]\t", output);
function selectError(event:SQLErrorEvent):void
  status.text = "Error loading data";
  selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);
  selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);
  trace("SELECT error:", event.error);
  trace("event.error.message:", event.error.message);
  trace("event.error.details:", event.error.details);

Your database system may well have a setting for character encoding when creating new databases. If you set that to unicode JDBC should store and retrieve UNICODE strings automatically.
As to the HTML side, you should generally use UTF-8 encoding. You need an editor which understands UTF-8. JSPs and servlets have ways of specifying the encoding which goes into the http headers. For static HTML pages you may have to add a header like:
<META http-equiv="Content-type" value="text/HTML; charset=UTF-8">
When receiving form data you need to do
request.setCharacterEncoding("UTF-8");

Similar Messages

  • Retriving data from database using JDBC and mysql.

    st=con.createStatement();
    st.executeUpdate("INSERT INTO temperature(`temp`) VALUES ('"+name+"')"); ResultSet rs = st.executeQuery("Select * from temperature");
    String s1="";
    while(rs.next())
    s1= rs.getString(1);
    document.write(s1+"-----------------------------");
    }when i am retriving data from data base i am getting data which i inserted before.how to display present inserted data? i heard we should use scrollable.can any one how to do this.
    Date&time: Thu Feb 28 18:41:40 PST 2008 -----------------------------NANDA----------------------------
    [[email protected]----1name=2name=3name=4name=5name=6-----------------------------
    1123456-----------------------------123456-----------------------------1,2,3,4,5,20-----------------------------

    Hi,
    st=con.createStatement();
    st.executeUpdate("INSERT INTO temperature(`temp`) VALUES ('"+name+"')");
    //Changes in the query
    ResultSet rs = st.executeQuery("Select * from temperature where temp ='"+name+"' ");
    String s1="";
    while(rs.next())
    s1= rs.getString(1);
    document.write(s1+"-----------------------------");
    //Select * from temperature where temp ='"+name+"'
    The above query which results the last updated information

  • How save & retrive data from database using flex, coldfusion, sql server

    hi , i am very new in flex, i am trying to insert data in
    database using flex2, coldfusion, sql server. any one can help me
    please. or give me any example.

    Hi try to goto the following sites, you will get some
    direction to think
    http://weblogs.macromedia.com/pent/archives/2006/11/example_of_flex.cfm
    http://pdxphp.org/node/258
    Good Luck

  • How to edit bitmap which is imported in flash using xml and save the edited bitmap back to xml in flash.

    hi all
    It would be appreciated if any one let me know how to edit
    bitmap which is imported in flash using xml and save the edited
    bitmap back to xml in flash.
    Is it posible to save the bitmap data in flash?
    thanks in advance

    Yes you can... but like I said before you need to upload the
    data from the changes you make to a server.
    In terms of the solution... its unlikely that you'll find one
    specifically for your needs. You will have to learn whatever you
    don't know how already and maybe adapt some existing examples to
    your needs.
    To change the visual state of a movie clip... you just do all
    the regular things that you want to do to it using flash... scale,
    rotation, drawing API , textfields etc in actionscript. If you
    don't know how to how to do that stuff, then you need to learn that
    first. That's basic actionscript.
    You can capture the visual state of a movieclip using the
    BitmapData class. That includes a loaded jpeg. You can also
    manipulate bimatp data using the same class. You should read up on
    that if you don't know how to use it or check out the examples
    below for uploading info.
    For uploading to the server:
    Here's an as2 solution that took 15 secs to find using
    google:
    http://www.quasimondo.com/archives/000645.php
    If you're using as3, google search for "jpeg encoder as3" and
    look through that info. There are also historical answers in the
    forums here related to this type of thing that might help as
    well.

  • Question regarding Polling data from database using DB Adapters in BPEL

    Hi,
    I have the following question regarding Polling data from database using DB Adapters in BPEL -
    If I am selecting data from multiple tables/view to ultimately generate hierarchical xml document, is there a way that I specify polling all of these tables/views. Is polling limited only to one table/view?
    Thanks
    Ravi

    Hi Ravi,
    your question seems to have been answered for the question of polling a set of tables with one as the root, and getting back a hierarchical xml representing multiple related tables.
    However you can also poll for changes to both the root table and its related tables. Not sure if this was your question or the one already answered. If the former please check out the sample
    bpel/samples/tutorials/122.DBAdapter/advanced/polling/PollingForChildUpdates
    Thanks
    Steve

  • Can I copy one frame of a movie using iMove and save the frame as a file that can be printed like a picture?

    Can I copy one frame of a movie using iMovie and save the frame as a file that can be printed like a picture?  If so, how do I do that?

    You could if you want a postcard sized print.
    Printers need a lot more "dots" per inch and even a 1920X1080 video doesn't have enough "dots" to make more than a postcard.
    Look at the "More Like This" links at the right side of this page for instructions.

  • Explain How delivery date is calculated using backward and forward schedul

    How can anyone please explain how delivery date is calculated using forward and backward scheduling
    I want to have it broken down into the following steps
    for eg for delivery date calculation following dates are used
    Material Availabilty Date
    Material Staging Date
    Pick/pack time
    Transportation PLanning date
    Loading date
    Goods issue date
    Transit Date
    Delivery Date
    Can some one please give me an example and explain wht these dates are
    for eg customer needs delivery date on  11/20/2008
    how would the system cacluate whether it can meet the delivery date using backward scheduling
    and if it doesnt meet how does the system do the forward scheduling
    also i am not clear with the following dates
    material avaialibilty date
    material staging date
    transportation date
    can some one please explain me all this in detail
    Thanks

    Hi,
    Basically this is the CRSD(Customer requested ship date logic)logic in which system calculates the ship date depends upon the material availability. If material is available system calculates ship date on the basis of master data maintained in customisation.Master data is maintained in the  following link.
    If material is not available then system takes into consideration vendor delivery date & then calculate customer ship date.
    Please go through the link in SPRO
    LE-Shipping -Basic shipping functions-Scheduling -Delivery scheduling & Transportation scheduling-Maintain duration.
    In customisation following data is maintained
    Material Availabilty Date
    Material Staging Date
    Pick/pack time
    Transportation PLanning date
    Loading date
    Goods issue date
    Transit Date
    Delivery Date
    Hope you got the idea of CRSD calculation
    Regards,
    Prashant.

  • Is it possible to save a data portion starting from when a "save" button is pressed?

    Hi,
    The below attached vi acquires data from a sensor. The sensor signal output can be reset to zero and the data saved into a file. However, the saved data comprises the data portion starting from when the vi starts running until the "stop" button is pressed. Is it possible to save the data portion starting from when the "save" button until the "stop" button are pressed?
    Best regards,
    Ninjatovitch
    Solved!
    Go to Solution.
    Attachments:
    Sensor Signal Acquisition.vi ‏52 KB

    this should be in 8.2
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome
    Attachments:
    RandomNumberSubVI.vi ‏8 KB
    savefilewhenselected.vi ‏11 KB
    f.txt ‏1 KB

  • Chart - PREVIEW and SAVE buttons disabled.

    I am using BI Publisher Desktop with WORD 2007 on VISTA. When I attempt to add a chart to a rtf template, the PREVIEW and SAVE buttons are disabled. I can move data fields from the Data section into the Layout Section, select chart type, even the style. Everything appears to work just fine but I can not preview or save. The template file is not in any restricted folder. I can add a table, then save and preview the document just fine.
    I have even openned some of the samples that came with the download and when I view the properties on an existing chart, I see the same disabled buttons.

    Which menu path are you using?
    Are the items available for personalization?

  • How to use Checkbox  and radio buttons in BI Reporting

    Hi BW Experts,
       My Client has given a report in ABAP format and the report has to be develop in BI.It contains Check boxes and the radio buttons. I don’t know how to use Checkboxes and radio buttons in Bex.For using this option, do we need to write a code in ABAP.Please help on this issue.
    Thanks,
    Ram

    Hi..
    Catalog item characteristic
    - Data element
    - Characteristic type
    Entry type
    List of catalog characteristics
    Designer
    Format (character)
    Standard characteristic
    Alternative: Master characteristic
    (used for automatic product
    assignment)
    Simple entry field
    Alternatives:
    Dropdown listbox or radio button
    list

  • Disable Print and Save button in tooldbar in AxAcroPDFLib.AxAcroPDF

    Hi,
    I am using AxAcroPDFLib.AxAcroPDF  to display pdf files in my C# winform application.
    I have a requirement now that for some documents alone i should disable the print and save button in the toolbar of my AxAcroPDFLib.AxAcroPDF window.
    I need the rest of the buttons in the toolbar to be working.
    Can someone please tell me how to disable these buttons in my c# code. What property i hsould set to my AxAcroPDFLib.AxAcroPDF object to make this happen.
    Hoping to get an answer soon.
    Thanks and Regards,
    Dinesh.N

    There is nothing you can do via the C# APIs to disable these buttons.

  • How to disable Save and SaveAs Button in Adobe Reader ??

    I am having Dynamic XML Form (XFA based) designed on LC Designer ES2
    I Want to disable Save and SaveAs button  whenever it would be opened in Adobe Reader only.
    Other way around, i want to provide only facility to save form programmatically through Javascript to apply validation.
    Plz help
    Thnx in advance..!!

    I can apply folder level java script ...But How to handle this way on CLIENT SIDE..???

  • Use "next" and "previous" buttons in two scroll panes

    Hello, I have a question about how to use next and previous buttons in two scroll panes. In fact, I plan to display two similar files (HTML) in two scroll panes seperately. the purpose is to find their differences, highlight these differences and finally traverse these differences one by one by using next and previous buttons.
    To realize this function, how should I mark their differences so that next and prevous buttons can recognize their locations? does anyone have idea?
    Thank you very much.

    Can "focus" resolve this problem? But how should I add focus to a line in one HTML files? Thank you.

  • Saving data in database by using MM17

    I have customised fields in MARA table. I want to save the data in database by using Mass transaction MM17. Can any one can give the solution.

    Please do not post the same question more than once.  Please read the Terms of Engagement.  I have deleted your duplicate posts.

  • How to convert UIView object to NSData and vise-versa  for saving it in database using sqlite

    I am using sqlite for my project which stores all the data including text fields , id , and one UIVIew object in a column having BLOB datatype .
    Now while retriving the data i use
    const char *raw = sqlite3_column_blob(selectstmt, 3);
    int rawLen = sqlite3_column_bytes(selectstmt, 3);
    NSData *data = [NSData dataWithBytes:raw length:rawLen];
      view =[NSKeyedUnarchiver unarchiveObjectWithData:data];
    where data is NSData obj n view is UIView obj ,
    also while inserting data  i use ,
    NSData *data=[[NSData alloc]init];
        data=[NSKeyedArchiver archivedDataWithRootObject:view];
       // [data dataForView:notes.view];
        sqlite3_bind_blob(updateStmt, 2, [data bytes], [data length], SQLITE_TRANSIENT);
    But this is not working properly ...  the Data object is giving some length,
    while using the view the view object is null
    is there any other solution to do the same ?

    There's a ton of information here: [http://www.json.org/] and I can't believe you didn't find that site yourself.

Maybe you are looking for

  • How to show data from sharepoint list in mm dd yyyy format using Server Object Model

    In SharePoint 2010 List "Employee", Colum Name "JoinDate"  has stored data in  (01/31/2014 12.00 PM) mm\dd\yyyy hr:mm PM format. How to display this data in mm\dd\yyyy only using C# on custom web part?

  • Language problems

    Hi, since today the language here on kde is half in english and half in german and it should be just german. In the KDE system-Settings I've set the country to germany and the preferred language to german but nevertheless parts of the KDE menu and e.

  • Save JTable's data

    hello, Can i save the JTable's data in binary and reload them? give me some suggestions please Now i save the JTable's data as txt format,but i want to save a password's MD5 result before them(its format is binary).i want to save them in one format,h

  • Cannot update to version 9,0,124,0

    How can I force the installation of a Flash Player update to version 9,0,124,0? After installing Flash Player update version 9,0,124,0 although declared successful the previous working version 9,0,47,0 remains in place. Un-installing version 9,0,47,0

  • CS6 METADATA QUESTIONS

    CS6 METADATA QUESTIONS Working with record album saved in a wave format, on a computer running windows 7 I break the album into individual songs using markers  which I name the title of each song, I check the include metadata box when I export each m