我正在制作一个需要在登录页面输入用户名和密码的应用程序。 如何从黑莓10级联数据库中检索用户名和密码?请提一下代码......
答案 0 :(得分:0)
通过结果集从数据库中获取require用户和密码。
String user=usertx.getText();
char[] password=pswdtx.getPassword();
String pswd=String.valueOf(password); \\here is important to put a char password in string.`
我们通过以下方式调用require用户及其密码:
Resultset rs= stmt.excuteQuery("SELECT * FROM USERS WHERE NAME='"+user+"' AND PASSWORD='"+pswd+"'");
此代码将仅获取所选用户的行和他在行上的信息,并将其设置为(rs)。代码rs.next()
:
while(rs.next()){
rsuser=rs.getString("NAME"); //get user and set it in rsuser.
rspswd=rs.getString("PASSWORD");} //get password and set it in rspswd.
if ((user.equals(rsuser)) && (pswd.equals(rspswd))){ //the equevlant statment.
JOptionPane.showMessageDialog(null, "Username and Password exist");}
else {
JOptionPane.showMessageDialog(null, "Please Check Username and Password ");}
}
这里是完整的代码:
private void submitActionPerformed(java.awt.event.ActionEvent evt) {
try {
String user=usertx.getText();
char[] password=pswdtx.getPassword();
String pswd=String.valueOf(password);
String rsuser=null;
String rspswd=null;
String Q="SELECT * FROM USERS WHERE NAME='"+user+"' AND PASSWORD='"+pswd+"'";
rs=stmt.executeQuery(Q);
while(rs.next()){
rsuser=rs.getString("NAME");
rspswd=rs.getString("PASSWORD");}
if ((user.equals(rsuser)) && (pswd.equals(rspswd))){
JOptionPane.showMessageDialog(null, "Username and Password exist");}
else {
JOptionPane.showMessageDialog(null, "Please Check Username and Password ");}
}
catch (SQLException ex) {ex.printStackTrace();}
}
答案 1 :(得分:-1)
将以下行添加到.pro文件中 LIBS + = -lbbdata
然后你可以编写以下代码:
QVariant searchResult;
QVariantList searchList;
QString userName, password;
bb::data::SqlDataAccess sda(QDir::currentPath() + "/app/native/assets/sample.sqlite");
searchResult = sda.execute("select * from usersTable where userId=5");
searchList = searchResult.value<QVariantList>();
userName = searchList.at(0).toMap()["name"];
password = searchList.at(0).toMap()["password"];