如何在node.js中插入用户名和密码到表之前检查表的用户ID? [英] How to check userid in table before inserting userid and password into tables in node.js?

查看:242
本文介绍了如何在node.js中插入用户名和密码到表之前检查表的用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在创建Android应用程序,连接到数据库SQLDB和我插入用户名,用户名和密码到表。插入到表之前,我有检查表中已经存在如果没有的话我必须插入用户ID。
以及如何响应回调注册成功,如果正确插入,或者用户ID已经存在我的Andr​​oid应用程序。

这是我的node.js code:

  VAR前preSS =要求('前preSS');
应用=前preSS();
VAR ibmbluemix =要求('ibmbluemix')
VAR ibmdb =要求('IBM_DB');
VAR HTTP =要求('HTTP');
VAR URL =要求('URL');
变种记录器= ibmbluemix.getLogger();VAR PORT =(process.env.VCAP_APP_PORT || 8000);
VAR HOST =(process.env.VCAP_APP_HOST ||'localhost'的);VAR queryData = NULL;VAR服务名='SQLDB';如果(process.env.VCAP_SERVICES){
VAR ENV = JSON.parse(process.env.VCAP_SERVICES);
DB2 = ENV ['SQLDB'] [0] .credentials;
}
其他{
console.error(FOR DB连接信息NOT FOUND);
}


解决方案

你应该使用,而不是使用自动增量或序列创建它们,例如自动生成的ID。
无论如何,你可以简单地使用用一个简单的查询检查ID已经被

  SELECT ID FROM USER02130.USER_DETAILS WHERE ID =<&ID GT;

如果它返回一个值,你可以返回一个错误给您的应用程序,否则,你就可以运行插入查询
INSERT INTO USER02130.USER_DETAILS()VALUES(
并用成功code返回的ID(例如)。
您还可以自定义返回codeS,如果你愿意,等等。

Am creating android app, that connects to SQLDB database and am inserting username, userid and password into table. Before inserting into table i have check the userId already existing in the table if not then i have to insert. and how to callback response "registration successful" if inserted correctly or "userid already exist" to my android app.

This is my node.js code:

  var express   = require('express');
app         = express();
var ibmbluemix  = require('ibmbluemix') 
var ibmdb = require('ibm_db');
var http = require('http');
var url = require('url');
var logger = ibmbluemix.getLogger();

var PORT = (process.env.VCAP_APP_PORT || 8000);
var HOST = (process.env.VCAP_APP_HOST || 'localhost');

var queryData = null;

var serviceName = 'SQLDB';

if (process.env.VCAP_SERVICES) {
var env = JSON.parse(process.env.VCAP_SERVICES);
db2 = env['sqldb'][0].credentials;
}
else{
console.error("INFORMATION FOR DB CONNECTION NOT FOUND");
}

解决方案

you should use autogenerated ids instead of creating them, for example using autoincrement or sequences. Anyway, you could simply use a simple query checking the id is already in use by

SELECT ID FROM USER02130.USER_DETAILS WHERE ID = <ID>

and if it returns a value you can return an error to your application, otherwise you can then run the insert query INSERT INTO USER02130.USER_DETAILS () VALUES ( and return the id (for example) with a success code. You can also customize the return codes, if you want, and so on.

这篇关于如何在node.js中插入用户名和密码到表之前检查表的用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆