package mianshi;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import com.microsoft.jdbc.sqlserver.SQLServerDriver;
public class CK_dl extends JFrame{
String wbk;
String sfz;
Connection con;
Statement sql;
ResultSet res;
public Connection getConnection() {
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;Databasename=mianshixt", "sa","123456");
System.out.println("OK");
sql=con.createStatement();
res=sql.executeQuery("select*from dl_Sfz");
while (res.next()) {
sfz=res.getString("Sfz");
System.out.println(sfz);
}
}catch(Exception e){
e.getStackTrace();
}
return con;
}
public CK_dl(){
JFrame jf=new JFrame();
Container con=jf.getContentPane();
final JTextField jt=new JTextField("输入");
JButton jb=new JButton("按扭");
jf.setSize(500, 500);
con.add(jt,BorderLayout.NORTH);
con.add(jb,BorderLayout.SOUTH);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
wbk=jt.getText();
if(wbk.matches(sfz)){
JOptionPane.showMessageDialog(null, "通过验证");
}else{
JOptionPane.showConfirmDialog(null, "验证失败");
}
}
});
jf.setVisible(true);
jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public static void main(String[] args) {
CK_dl C=new CK_dl();
C.getConnection();
}
}
不知道怎么判断 自己输入数据的是否在数据库中出现了 谁能告诉我怎么写