6 Replies Latest reply on Jun 1, 2009 3:35 AM by *Prashant Shelke*

    which data type is there in flex to insert clob data in the database

    sweetysk Level 1

      Hello,

       

              To insert routepath of the map I have declared one variable in the flex application and I am inserting that variable in database i.e.,I am inserting clob data type. I have to return clob data from flex application to java code. so that I can insert clob data in database.
      Is there any datatype in flex which is equivalent datatype as clob?

      Can anyone help me?

       

      Thanks in Advance.

        • 2. Re: which data type is there in flex to insert clob data in the database
          varun rathore Level 1

          Basically there is no specific data type in flex to insert Blob , you can though use * type of variable as follows

           

          var clobType : * ;

           

          now this type of variable will accept data of any type

          You can seralize it on server end and save it in Blob type and then while retriving you can deseriale it and send it back to flex.

           

          Cheers

           

          Varun Rathore

           

          http://www.vrathore.blogspot.com

          • 3. Re: which data type is there in flex to insert clob data in the database
            sweetysk Level 1

            I am getting the below error.

             

            code:
            Server.ResourceUnavailable

            Message:
            Cannot invoke method 'storeDirection'.

            Detail:
            The expected argument types are (java.sql.Clob) but the supplied types were (java.lang.String) and converted to (null).

             

            Please find the attached file for the mxml code.

             

            And this is the code written in java class

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

            public

             

             

            void

            storeDirection(java.sql.Clob direction){

            getConnection();

             

             

            try

            {

             

             

            query = "insert into testemp values(?)";

            pstmt = con.prepareStatement(query.toString());

             

             

            pstmt.setClob(1,direction);

             

             

            pstmt.executeUpdate();

            }

            catch

            (Exception e){

            e.printStackTrace();

            }

             

            finally

            {

             

             

            try

            {

             

             

            if(con != null

            )

             

             

            con.close();

             

             

            if(pstmt != null

            )

             

             

            pstmt.close();

            }

             

            catch

            (SQLException e){

            e.

            printStackTrace();

            }

            }

             

             

            Can anyone please help me?

             

            • 4. Re: which data type is there in flex to insert clob data in the database
              sweetysk Level 1

              I am getting the below error

               

              code:
              Server.ResourceUnavailable

              Message:
              Cannot invoke method 'storeDirection'.

              Detail:
              The expected argument types are (java.sql.Clob) but the supplied types were (java.lang.String) and converted to (null).

               

              The code snippets are..

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

              <?xml version="1.0" encoding="utf-8"?>

              <mx:Application

               

               

              xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" viewSourceURL="srcview/index.html"

              >

              <mx:RemoteObject

               

               

              id="emp" fault="faultHandler(event)" showBusyCursor="true" destination="FlexDb"

              >

               

               

              <mx:method name="storeDirection" result="resultHandler(event)"

              />

              </mx:RemoteObject>

               

               

              <mx:Panel backgroundColor="#FFFFFF" width="100%" height="100%" paddingLeft="5" paddingTop="5"

              >

               

               

              <mx:VBox width="100%" height="100%"

              >

               

               

              <mx:HBox width="100%"

              >

               

               

              <mx:TextInput id="from" text="600 N Lamar Blvd, Austin, TX" width="200"

              />

               

               

              <mx:Label text=" to "

              />

               

               

              <mx:TextInput id="to" text="320 E 6th St, Austin, TX" width="200"

              />

               

               

              <mx:Button id="submitButton" label="Go" click="processForm(event);"

              />

               

               

              </mx:HBox>

               

               

              <mx:UIComponent id="mapHolder" initialize="onHolderCreated(event);" resize="onHolderResized(event)" width="100%" height="100%"

              />

               

               

              <mx:Text id="description" text="" width="100%" textAlign="center" fontSize="18" height="40"

              />

               

               

              </mx:VBox>

               

               

              </mx:Panel>

               

               

               

              <mx:Script>

              <![CDATA[

               

               

              import

              mx.rpc.events.ResultEvent;

               

               

              import

              mx.rpc.events.FaultEvent;

               

               

              import

              com.google.maps.InfoWindowOptions;

               

               

              import

              com.google.maps.LatLng;

               

               

              import

              com.google.maps.LatLngBounds;

               

               

              import

              com.google.maps.Map;

               

               

              import

              com.google.maps.MapEvent;

               

               

              import

              com.google.maps.MapMoveEvent;

               

               

              import

              com.google.maps.overlays.Marker;

               

               

              import

              com.google.maps.overlays.MarkerOptions;

               

               

              import

              com.google.maps.interfaces.IPolyline;

               

               

              import

              com.google.maps.services.*;

               

               

               

              import

              flash.display.Loader;

               

               

              import

              flash.display.MovieClip;

               

               

              import

              flash.net.URLRequest;

               

               

              import

              mx.controls.Alert;

               

               

               

              private var

              map:Map;

               

               

              private var

              dir:Directions;

               

               

              private var

              steps:Array;

               

               

              private var

              stepIndex:uint;

               

               

              private var

              polyline:IPolyline;

               

               

               

              private function resultHandler(evt:ResultEvent):void

              {

              description.text = evt.message.toString();

              }

               

               

              private function faultHandler(fault:FaultEvent):void

              {

              Alert.show(

               

              "code:\n" + fault.fault.faultCode + "\n\nMessage:\n" + fault.fault.faultString + "\n\nDetail:\n"

              + fault.fault.faultDetail);

              }

               

               

              public function onHolderCreated(event:Event):void

              {

               

               

              this.map = new

              Map;

               

               

              this.map.key = "ABQIAAAAKLe0_mKipf1gsfnpmrQigRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ8RzJwVkCiFn9GUTtAjx6u8l92vA"

              ;

               

               

              this

              .map.addEventListener(MapEvent.MAP_READY, onMapReady);

              mapHolder.addChild(map);

              }

               

               

              private function onMapReady(event:Event):void

              {

              dir =

               

              new

              Directions();

              dir.addEventListener(DirectionsEvent.DIRECTIONS_SUCCESS, onDirLoad);

              }

               

               

              private function processForm(event:Event):void

              {

              dir.load(

               

              "from: " + from.text + " to: " + to

              .text);

              }

               

               

              private function onDirLoad(event:DirectionsEvent):void

              {

               

               

              var

              dir:Directions = event.directions;

               

               

              var

              startLatLng:LatLng = dir.getRoute(0).getStep(0).latLng;

               

               

              var

              endLatLng:LatLng = dir.getRoute(dir.numRoutes-1).endLatLng;

              polyline = dir.createPolyline();

               

              map.clearOverlays();

              map.addOverlay(polyline);

              map.addOverlay(

               

              new

              Marker(startLatLng));

              map.addOverlay(

               

              new

              Marker(endLatLng));

              map.setCenter(dir.bounds.getCenter(), map.getBoundsZoomLevel(dir.bounds));

               

              steps = [];

              stepIndex = 0;

              setControls(

               

              false

              );

               

               

              var msg:*;

               

               

               

              for (var r:int = 0; r < dir.numRoutes; r++) {

               

               

              var route:Route = dir.getRoute(r);

               

               

              for (var s:int = 0; s < route.numSteps; s++) {

               

               

              var step:Step = route.getStep(s);

              steps.push({

              start: step.latLng,

              index: step.polylineIndex,

              description: step.descriptionHtml +

               

              " (" + step.distanceHtml + ", "

              +

              step.durationHtml +

               

              ")"

               

              });

              msg = msg+ step.descriptionHtml +

               

              " (" + step.distanceHtml + ", " +step.durationHtml + ")\n"

              ;

              }

              Alert.show(msg);

              emp.storeDirection.send(msg);

              }

              }

               

               

              private function setControls(on:Boolean):void

              {

              from.enabled = on;

               

               

              to

              .enabled = on;

              submitButton.enabled = on;

              }

               

               

              public function onHolderResized(event:Event):void

              {

               

               

              this.map.setSize(new

              Point(mapHolder.width, mapHolder.height));

              }

              ]]>

               

               

              </mx:Script>

              </mx:Application>

               

               

              and coming to java code

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

              public

               

               

              void

              storeDirection(java.sql.Clob direction){

              getConnection();

               

               

              try

              {

              query = "insert into testemp values(?)";

               

               

              pstmt = con.prepareStatement(query.toString());

               

               

              pstmt.setClob(1,direction);

               

               

              pstmt.executeUpdate();

              }

               

              catch

              (Exception e){

              e.printStackTrace();

              }

               

              finally

              {

               

               

              try

              {

               

               

              if(con != null

              )

               

               

              con

              .close();

               

               

              if(pstmt != null

              )

               

               

              pstmt

              .close();

              }

               

              catch

              (SQLException e){

               

               

              e.printStackTrace();

              }

              }

              }

              Can anyone please help me?

               

               

               

               

               

               

               

               

               

               

               

               

              • 5. Re: which data type is there in flex to insert clob data in the database
                *Prashant Shelke* Level 4

                I think there is problem from where you are calling setDirection(Clob), while calling ensure you done casting properly.


                Thanks.

                • 6. Re: which data type is there in flex to insert clob data in the database
                  *Prashant Shelke* Level 4

                  I think data which you are sending from Actionscript(of type * ) is getting converted to String type so thats why its giving exceptions.

                  So try to cast to Clob/ Blob in JAVA.


                  referr


                  http://www.artima.com/forums/flat.jsp?forum=1&thread=22568&start=0

                  http://forums.sun.com/thread.jspa?threadID=349880&start=15

                  http://forums.sun.com/thread.jspa?threadID=349880


                  Thanks.