Insertion of values in database

前端 未结 1 1596
甜味超标
甜味超标 2020-11-30 15:52

Hey I am using IBM Worklight V6.2.I want to insert values into database

My Html Code is

 

Please Enter The Car Details

1条回答
  •  盖世英雄少女心
    2020-11-30 16:21

    You can't simply place the IDs of your inputs as the WL.client.invokeProcedure's parameters... You need to pass their value.

    For example:

    function loadFeeds1(){
        var invocationData = {
            adapter:"car2",
            procedure:"getuser",
            parameters:[$('#carnum').val(),$('#details').val()]
        };
    
        WL.Server.invokeProcedure(invocationData,{
            onSuccess :loadFeedsSuccess1,
            onFailure :loadFeedsFailure1,
        });
    }
    

    This is an end-to-end scenario, where I take 2 values from the HTML and insert them into the database. To re-create, you can you use the WorklightTraining.sql scheme provided in the Adapters sample project. You can see it works because after the 'success', if you will refresh the database - you'll see the new record.

    HTML:

    Test Insert Into Database



    main.js:

    function insertValuesToDB() {
        var invocationData = {
            adapter: 'insertValuesAdapter',
            procedure: 'insertValuesProcedure',
            parameters: [$('#value1').val(), $('#value2').val()]
        };
    
        WL.Client.invokeProcedure(invocationData, {onSuccess: insertSuccess, onFailure: insertFailure});
    }
    
    function insertSuccess() {
        alert("success");
    }
    
    function insertFailure() {
        alert("failure");
    }
    

    Adapter XML:

    ...
    ...
    
        
            
                com.mysql.jdbc.Driver
                jdbc:mysql://localhost:3306/worklight_training
                Worklight
                Worklight 
             
        
        
    
    
    
    ...
    ...
    

    Adapter implementation:

    var insertValuesProcedureStatement = WL.Server.createSQLStatement("INSERT INTO users(userId, firstName, lastName, password) VALUES (?,?, 'someLastName', 'somePassword')");
    
    function insertValuesProcedure(value1,value2) {
        return WL.Server.invokeSQLStatement({
            preparedStatement : insertValuesProcedureStatement,
            parameters : [value1,value2]
        });
    }
    

    0 讨论(0)
提交回复
热议问题