Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

Issue while inserting Data into Hana table using xsjs(through URL Parameter)

$
0
0

Hi Guys,

 

I have this code for inserting data into the Hana tables through URL.

 

var id = $.request.getParameter("id");

if (id === null) {

    $.response.setContentType("text/plain");

    $.response.addBody("id is null!");

}

 

var val1 = $.request.getParameter("val1");

if (val1 === null) {

    $.response.setContentType("text/plain");

    $.response.addBody("val1 is null!");

}

 

var output = {};

output.data = [];

 

var conn = $.db.getConnection();

conn.prepareStatement("SET SCHEMA \"TEST\"").execute();

 

var st = conn.prepareStatement("INSERT INTO \"TABLE1\" values(?,?)");

st.setString(1,id);

st.setString(2,val1);

st.execute();

conn.commit();

 

var record = [];

record.push(id);

record.push(val1);

output.data.push(record);

 

conn.close();

 

$.response.setContentType("text/json");

$.response.addBody(JSON.stringify(output));

 

 

Whenever I try to execute this I get an error.

As I have taken id as integer and val1 as double.

 

Insert_Error.JPG

 

But I modified the code and tried to insert it statically, I was succeeded.

 

//$.response.contentType = "text/html";

/* var id = $.request.getParameter("id");

if (id === null) {

    $.response.setContentType("text/plain");

    $.response.addBody("id is null!");

}

 

var val1 = $.request.getParameter("val1");

if (val1 === null) {

    $.response.setContentType("text/plain");

    $.response.addBody("val1 is null!");

}

 

var output = {};

output.data = [];

*/

var conn = $.db.getConnection();

conn.prepareStatement("SET SCHEMA \"Schema\"").execute();

var query= "INSERT INTO \"TABLE1\" values(117,16)";

var st =conn.prepareStatement(query);

 

 

//var query= 'insert INTO \"Schema\".\"TABLE1\"(id,val1) VALUES(11,15)';

//var query= 'create column table table3(id integer, val2 nvarchar(20))';

//var query= 'insert into table1 values(6,12)';

//var query= 'update table1 set val1=13 where val1=12 and id=6';

//var query ="insert into region values(600,'GULF','DUBAI')";

//var st = conn.prepareStatement(query);

//st.setString(1,id);

//st.setString(2,val1);

st.execute();

conn.commit();

 

//var record = [];

//record.push(id);

//record.push(val1);

//output.data.push(record);

 

conn.close();

 

//$.response.setContentType("text/json");

 

 

//$.response.setBody("This is the query:"+query);

//$.response.setBody("This is the query:"+st);

$.response.setBody(query);

 

 

And I got the proper output.


As You can see my code I have used diff ways to insert the value I was succeeded.

Kindly guide me to insert the value through URL .

 

Insert_Error_Value.JPG


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>