1

today i wanna try insert data to my oracle database but the data can't saved to database here my code

async function db () {
return new Promise( async (resolve, reject) => {
    try {
      console.log("processing")
      connection = await oracle.getConnection(konek);
      var result = await connection.execute(`INSERT INTO MS_PERANGKAT (SERIALNUMBER, SSID) VALUES (:1, :2)`, ['12333', 'Rupadana']);

      connection = connection.execute("SELECT * FROM ms_perangkat");

      resolve(connection)
    } catch (err) {
      reject(err)
    } finally {
      if (connection) {
        try {
          await connection.close();
        } catch(err) {
          reject(err)
        }
      }
    }
  })
}

db().then( async connection => {
  console.log(connection)
}).catch(err => {
  console.log('Error: ',err)
});

Here the output :

{
  metaData: [ { name: 'SERIALNUMBER' }, { name: 'SSID' } ],
  rows: [ [ '12333', 'Rupadana' ] ]
}

and here my Oracle Database

2
  • I agree with Wayan. I just want to comment that the explicit promise you're returning from db seems unnecessary. Async functions automatically return promises. If the function returns a value, then that value is used to resolve the promise. If the function throws an error, the promise is rejected with that error. See this series to learn more: jsao.io/2017/06/… Commented Dec 7, 2019 at 2:59
  • thank you @DanMcGhan for the Information :D Commented Dec 9, 2019 at 2:49

1 Answer 1

1

that happens because the query hasn't been committed

here the code:

var result = await connection.execute(`INSERT INTO MS_PERANGKAT (SERIALNUMBER, SSID) VALUES (:1, :2)`, ['12333', 'Rupadana'],{autoCommit: true});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.