7 Replies Latest reply on Jun 28, 2010 7:59 AM by VRPDeveloper

    updationg data from datagrid to database

    dhifallah Level 1

      Hi ,

      I 'm searching an example of code to update data from datagrid to database using an HTTPService and calling a servlet java.

       

      I have a mxml file which connect to database to fill the datagrid ( this works for me), the the user modify this datagrid and send the modification to update the database using an HTTPService to call a sevlet java (this don't work for me) ,

       

      can you help me please or send me some links for that

        • 1. Re: updationg data from datagrid to database
          dhifallah Level 1

          In my HTTPservice I have a request like this:

          <mx:HTTPService

           

           

          id="MiseAJourTable"

          url="

          http://localhost:8080/SupportStarwebJ2EE/ServletMiseAJourDataBase"

          useProxy="

          false" method="GET" resultFormat="e4x">

           

           

          <mx:request xmlns="">

           

          <branche_SVN>{branche_SVN}</branche_SVN>

           

           

          <environnement>{environnement}</environnement>

           

           

          <tag_version>{tag_version}</tag_version>

           

           

          <revision_ihm>{revision_ihm}</revision_ihm>

           

           

          <revision_metier>{revision_metier}</revision_metier>

           

           

          <date_initialisation>{date_initialisation}</date_initialisation>

           

           

          <version_cible>{version_cible}</version_cible>

           

           

          <lot_cible>{lot_cible}</lot_cible>

           

           

          <liste_organisme>{liste_organisme}</liste_organisme>

           

           

          </mx:request>

           

           

          </mx:HTTPService>

           

           

           

          What can I add in my resquet to get what is put in the datagrid , because in my servlet I wanted to display the value of my columns but I have the following ansow:

           

           

          Environnement=[object DataGridColumn]

          Tag_version=[object DataGridColumn]

          Revision_ihm=[object DataGridColumn]

          Revision_metier=[object DataGridColumn]

          Date_initialisation=[object DataGridColumn]

          Version_cible=[object DataGridColumn]

          Lot_cible=[object DataGridColumn]

          Liste_organisme=[object DataGridColumn]

           

           

           

          • 2. Re: updationg data from datagrid to database
            dhifallah Level 1

            I'm waitting for your suggestion please

            • 3. Re: updationg data from datagrid to database
              VRPDeveloper Level 3

              What are these {branche_SVN}, {environnement} etc...

               

              I beleive that you want to send data from datagrid as a request in HTTPService, then in request you need to write {datagrid1.environment}. Also use debugging tool like fiddler or Charles to know exactly what is passing in request.

               

              Hope it will solve your problem!!!

              • 4. Re: updationg data from datagrid to database
                dhifallah Level 1

                {branche_SVN}, {environnement} etc... are dataField in my datagrid,

                I used an HTTPService as the following :

                <mx:HTTPService

                 

                id="MiseAJourTable"

                url="

                http://localhost:8080/SupportStarwebJ2EE/ServletMiseAJourDataBase"

                useProxy="

                false" method="GET" resultFormat="e4x">

                 

                <mx:request xmlns="">

                 

                <branche_SVN>{branche_SVN}</branche_SVN>

                 

                <environnement>{environnement}</environnement>

                 

                <tag_version>{tag_version}</tag_version>

                <revision_ihm>{revision_ihm}</revision_ihm>

                <revision_metier>{revision_metier}</revision_metier>

                 

                <date_initialisation>{date_initialisation}</date_initialisation>

                 

                <version_cible>{version_cible}</version_cible>

                 

                <lot_cible>{lot_cible}</lot_cible>

                 

                <liste_organisme>{liste_organisme}</liste_organisme>

                 

                </mx:request>

                 

                </mx:HTTPService>

                 

                 

                and here is my servlet java:

                 

                 

                .................

                protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                 

                 

                String connectionURL =

                "jdbc:mysql://10.0.10.33:3306/Supportweb";

                Connection connection=

                null;

                response.setContentType(

                "text/html");

                PrintWriter out = response.getWriter();

                 

                 

                String branche_SVN = request.getParameter(

                "branche_SVN");

                String environnement = request.getParameter(

                "environnement");

                String tag_version = request.getParameter(

                "tag_version");

                String revision_ihm = request.getParameter(

                "revision_ihm");

                String revision_metier = request.getParameter(

                "revision_metier");

                String date_initialisation = request.getParameter(

                "date_initialisation");

                String version_cible = request.getParameter(

                "version_cible");

                String lot_cible = request.getParameter(

                "lot_cible");

                String liste_organisme = request.getParameter(

                "liste_organisme");

                 

                System.

                out.println("branche_SVN= "+ branche_SVN);

                System.

                out.println("Environnement="+ environnement);

                System.

                out.println("Tag_version="+ tag_version);

                System.

                out.println("Revision_ihm="+ revision_ihm);

                System.

                out.println("Revision_metier="+ revision_metier);

                System.

                out.println("Date_initialisation="+ date_initialisation);

                System.

                out.println("Version_cible="+ version_cible);

                System.

                out.println("Lot_cible="+ lot_cible);

                System.

                out.println("Liste_organisme=" +liste_organisme);

                try

                 

                 

                {

                 

                // Load the database driver

                Class.forName(

                "com.mysql.jdbc.Driver");

                 

                // Get a Connection to the database

                connection = DriverManager.getConnection(connectionURL,

                "", "");

                connection.setAutoCommit(

                false);

                 

                String sql =

                "insert into gestion_environnement_bis values (?,?,?,?,?,?,?,?,?)";

                Statement stmt = connection.createStatement();

                stmt.executeUpdate(sql);

                connection.commit();

                 

                 

                 

                out.println(

                " la base de donnée a était mise à jour ");

                 

                }

                 

                catch(ClassNotFoundException e){

                out.println(

                "Couldn't load database driver: " + e.getMessage());

                }

                 

                catch(SQLException e){

                out.println(

                "SQLException caught: " + e.getMessage());

                }

                 

                catch (Exception e){

                out.println(e);

                }

                 

                finally {

                 

                // Always close the database connection.

                 

                try {

                 

                if (connection != null) connection.close();

                }

                 

                catch (SQLException ignored){

                out.println(ignored);

                }

                }

                }

                }

                 

                 

                 

                • 5. Re: updationg data from datagrid to database
                  VRPDeveloper Level 3

                  According to me, You are not sending request parameters properly .. You should send {datagridname.dataprovider.datafieldname}.

                  Try it!!!

                  • 6. Re: updationg data from datagrid to database
                    dhifallah Level 1

                    I tried it

                     

                     

                    <branche_SVN>{itemDG.dataprovider.branche_SVN}</branche_SVN>

                     

                    but I have the following error:

                    1119: Accès à la propriété dataprovider peut-être non définie, via la référence de type static mx.controls:DataGrid.

                    ==> that's mean it can not acced  to dataprovider

                     

                     

                    here is my datagrid :

                    <mx:DataGrid id="itemDG" dataProvider="{dpValue}" itemEditEnd="getCellInfo(event);" editable="true" width="1411" height="297" y="67.45" x="9.15">

                     

                     

                    and my dpValue is:

                     

                    [

                     

                    Bindable]

                     

                    private var dpValue:Array = [

                    { label:

                    "C1-devel", data:"C1-devel" },

                    { label:

                    "C2-devel", data:"C2-devel"},

                    { label:

                    "C3-devel", data:"C3-devel"},

                    { label:

                    "C1-assbl", data:"C1-assbl"},

                    { label:

                    "C2-assbl", data:"C2-assbl"},

                    { label:

                    "C3-assbl", data:"C3-assbl"},

                    { label:

                    "C1-qualf", data:"C1-qualf"},

                    { label:

                    "C2-qualf", data:"C2-qualf"},

                    { label:

                    "C3-qualf", data:"C3-qualf"},

                    { label:

                    "Maintq", data:"Maintq"},

                    { label:

                    "Maintd", data:"Maintd"},

                     

                    ];

                     

                     

                     

                    • 7. Re: updationg data from datagrid to database
                      VRPDeveloper Level 3

                      Have you looked into Charles or fiddler... what request parematers are passing. if you get those then it would be more clear.