比较文本字段值和数据库值 [英] Compare textfield value with database value

查看:155
本文介绍了比较文本字段值和数据库值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我在创建应用程序时需要帮助,我创建了一个数据库并将其连接到我的应用程序,当我在文本字段中输入任何ID时,数据库中包含具有ID,名称,...等字段的管理器表,它必须比较文本字段的值数据库值我该怎么做.
提前thnx.

hello.
I need help in creating my application , i create a database and connect it to my application my database contain manger table having a id, name,....etc of fields when i enter any id in textfield it must compare the value o textfield with database values how can i do this.
thnx in advance .

推荐答案

-将ID设为DB的键值
-提取具有所需ID的数据集
-比较任何

还是您需要一个SQL命令来检索重复项?无论如何,我都会添加一个SQL标记.
- Make ID the Key value of DB
- Fetch Dataset with the desired ID
- compare to whatever

Or do you need a SQL-Command for retrieving duplicates? I''ll add a SQL-Tag anyway.


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:MyDSN","sa","sa");PreparedStatement st=con.prepareStatement("select id from manger");
ResultSet rs=st.ExecuteQuery();
String ID1=JTextField1.getText();
String ID2=rs.getString("id");
if(ID1.equals(ID2))
{
  //ID matched...
  // Do whatever you want...
}
else
{
  //ID do not match...
  // Throw error message...
}

/*
Note:--- 
1) import java.sql.*;
2) import javax.sql.*;
3) MyDSN is the name of the Data Source.
4) sa is the id for SQL server Authentication and sa is the password.
5) JTextField1 is the ID of Text Box on your form.
*/


这篇关于比较文本字段值和数据库值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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