모든 입력은 인정 될 것입니다.ODBC & Node.js를 사용하여 데이터 입력
나는 ODBC 연결 문자열을 사용하여 node.js.s와 sql 데이터베이스를 연결하고 있습니다. 성공적으로 연결을 설정하고 데이터베이스를 쿼리 할 수 있지만 데이터를 삽입 할 때 문제가 발생합니다.
는 ODBC 플러그인
는 여기에서 찾을 수 있습니다 :var db = require("odbc")()
, cn = "Driver={ODBC Driver 13 for SQL Server};Server=host:insert-name.database.windows.net,insert-port;Database=insert-database-name;Uid=insert-uid;Pwd=insert-password;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
;
//Blocks until the connection is open
//Blocks until the connection is open
db.openSync(cn);
//Blocks while preparing the statement
db.prepare("INSERT INTO Contact (FirstName, LastName, Country, User, Email, PrivacyAgreement, PhoneNumber) VALUES (?,?,?,?,?,?,?)", function (err, stmt) {
if (err) {
//could not prepare for some reason
console.log(err);
return db.closeSync();
}
console.log(stmt);
//Bind and Execute the statment asynchronously
stmt.execute(['first','last','country_name', 1, '[email protected]', 1, '9999999999'], function (err, result) {
result.closeSync();
console.log(result);
//Close the connection
db.closeSync();
});
})
참고 : 여기에
var db = require("odbc")()
, cn = "DRIVER={FreeTDS};SERVER=host;UID=user;PWD=password;DATABASE=dbname"
;
//Blocks until the connection is open
db.openSync(cn);
db.prepare("insert into hits (col1, col2) VALUES (?, ?)", function (err, stmt) {
if (err) {
//could not prepare for some reason
console.log(err);
return db.closeSync();
}
//Bind and Execute the statment asynchronously
stmt.execute(['something', 42], function (err, result) {
result.closeSync();
//Close the connection
db.closeSync();
});
})
내 코드입니다 : 여기
https://www.npmjs.com/package/odbc 내가 다시 노력하고있어 예입니다 ' User '및'PrivacyAgreement '는 비트 데이터 유형 (부울)이고 나머지는 varchar입니다.
ODBCStatement { queue: SimpleQueue { fifo: [], executing: true } }
/path/to/file/insert.js:22
result.closeSync();
^
형식 오류 :
이있는, 나는 다음과 같은 오류 얻으려면 err
가 발생하기 때문에 stmt.execute
에 의해 반환 정의되지 않은