Skip to Content
avatar image
Former Member

HANA CLOUD PLATFORM

Hello Experts,

I am new to HANA

I have created a code, which inserts entries into table manually ( on URL).

=======================

Code is as below :

var ID = $.request.parameters.get("ID");

if (ID === null) { 

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

  $.response.setBody("ID is null!") ;

  } 

  var VAL1 = $.request.parameters.get("VAL1"); 

  if (VAL1 === null) { 

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

  $.response.setBody("VAL1 is null!");

  } 

  var output = {}; 

  output.data = []; 

  var conn = $.db.getConnection();

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

var st = conn.prepareStatement("INSERT INTO \"sxxxxxxxxxxtrial.vinni.insert.SAPSF::TEST\"  values(?,?)");

st.setString(1,ID); 

st.setString(2,VAL1);

st.executeQuery();

st.execute(); 

  conn.commit(); 

  var record = []; 

  record.push(ID); 

  record.push(VAL1); 

  output.data.push(record); 

  conn.close(); 

================================

I have also created hdbtable as below,

=======================

table.schemaName = "NEO_xxxxxxxxxxxxxx";

table.tableType = COLUMNSTORE;

table.columns = [

{name = "ID"; sqlType = INTEGER; nullable = false;},

{name = "VAL1"; sqlType = DECIMAL; nullable = false; precision = 12; scale = 3;}];

table.indexes = [ {name = "INDEX1"; unique = true; indexColumns = ["VAL1"];}];

table.primaryKey.pkcolumns = ["ID"];

Created xsaccess, xsapp, xsprivileges,model_access.hdbrole files.

When I click the URL in xs applications ( added id=5&val1=7 to URL)

=====================================

Below is the error I am facing :

================================

InternalError: dberror(PreparedStatement.execute): 301 - unique constraint violated: Table(sxxxxxxxxxxxxtrial.vinni.insert.SAPSF::TEST) at ptime/session/eapi/jdbc/ExternalStatement.cc:927 (line 22 position 0 in /sxxxxxxxxxxtrial/vinni/insert/SAPSF/insert.xsjs)

Could you please help me out.

Thanks ,

VINNI

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 03, 2015 at 05:40 AM
    11

    Hello Vinni,

    what entries are already available in your table? According to the message a unique constraint is violated which could be either a violation of your primary key or your unique "INDEX1".

    Best Regards,

    Florian

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Florian Pfeffer

      Hi Florian, I was mistaken while typing.  I have mentioned functions in xsjs file itself.

      Columns - I have created only one column and trying to insert from jsonapi into that table.

      error :{'data":[['null']]}

      If I enter value in URL like id=56, I am able to see the entry in table and array . But My task is not to insert value by entering manually, It should read the data from  jsonapi an table and insert the value into table.

      functions in xsjs file :

      var dest = $.net.http.readDestination("xxxxx","xxxx");

      var client = new $.net.http.client ();

      var req = new $.web.WebRequest($.net.http.GET,"id");

      ( I have tried without giving id in the above statement)

      var response = client.getResponse();