import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;public class IdentityCard {
public static void main(String []args) {
MyFrame fm = new MyFrame("身份证查询系统");
fm.setSize(300,280);
fm.setResizable(false);
fm.setVisible(true);


}
}class MyFrame extends JFrame implements ActionListener{ 
 final int list[]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
     TextField t1=new TextField ("460022198608317015",18);
 TextField t2=new TextField ("",18);
 JButton b1 = new JButton("查 询");
 String addr= "海南省文昌市";
 String born;
 String sex ;
 JLabel j1 = new JLabel();
 JLabel j2 = new JLabel();
 JLabel j3 = new JLabel();
 JLabel j4 = new JLabel();
 JLabel j5 = new JLabel();
 JLabel j6 = new JLabel();
 JLabel j7 = new JLabel();
 JLabel s1 = new JLabel();
 JLabel s2 = new JLabel();
 JLabel s3 = new JLabel();
 Container con = getContentPane();
 
 public MyFrame(String s) {
super(s);

t2.setEditable(false); 
setLocation(380,260);
con.setLayout(null);
j1.setText("15位或18位身份证");
con.add(j1);
j1.setBounds(12,14,200,16);
con.add(t1);
t1.setBounds(14,32,150,18);
j2.setText("15位对应的18位号码");
con.add(j2);
j2.setBounds(14,52,150,16);
con.add(t2);
t2.setBounds(14,70,150,18);
con.add(b1);
b1.setBounds(180,52,65,20);
b1.addActionListener(this);
//System.out.println(born);
j3.setText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
con.add(j3);
lable:
j3.setBounds(1,95,300,1);
j4.setText("号码信息");
con.add(j4);
j4.setBounds(12,100,150,16);
j5.setText(" 号码归属地 :");
con.add(j5);
j5.setBounds(14,140,150,16);
s1.setText(addr);
con.add(s1);
s1.setBounds(100,140,200,16);
j6.setText("出生日期 :");
con.add(j6);
j6.setBounds(14,170,150,16);
s2.setText(born);
con.add(s2);
s2.setBounds(100,170,200,16);
j7.setText("性别 :");
con.add(j7);
j7.setBounds(14,200,150,16);
s3.setText(sex);
con.add(s3);
s3.setBounds(100,200,200,16);
}
public void actionPerformed(ActionEvent e) {


if(e.getSource() == b1) {
String request = t1.getText();
String show1 = null;
String temp = null;
if(request.length()!=15 && request.length()!=18) {
  Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "您输入的身份证号码位数有误", "错误警告", 
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
}
     char[] by = new char[request.length()];
     by = request.toCharArray();
     for(int i=0;i<by.length;i++) {
     if(Character.isLetterOrDigit(by[i])) {
      temp = new String (by);
    
    
     }
     else {
    
     Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "身份证号码必须为数字或最后一位是x", "错误警告", 
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
     }
      
     }
     if(temp.length() == 15) {
    
        
        String s1=temp.substring(0,6);
       // System.out.println(s1);
                   String s2=temp.substring(6,15);
                   //System.out.println(s2);
                   temp = s1.concat("19").concat(s2);
                     // System.out.println(temp);
                   int N = 0;
                   int R = 0;
                   String T = null;
                   int[] n=new int[17];
                   for(int i=0;i<17;i++){
                       n[i]=Integer.parseInt(temp.substring(i,i+1));
                       N=N+n[i]*list[i];
                   }
                //  System.out.println(N);
                   //N=N+(2*1+1*9);
                   R=N%11;
                 // System.out.println(R);
                   switch(R){
                       case 0:T="1";break;
                       case 1:T="0";break;
                       case 2:T="X";break;
                       case 3:T="9";break;
                       case 4:T="8";break;
                       case 5:T="7";break;
                       case 6:T="6";break;
                       case 7:T="5";break;
                       case 8:T="4";break;
                       case 9:T="3";break;
                       case 10:T="2";break;
                   }
                  temp = temp.concat(T); 
                  t2.setText(temp);
     }
     else {
      int N = 0;
                   int R = 0;
                   String T = null;
                   int[] n=new int[17];
                   for(int i=0;i<17;i++){
                       n[i]=Integer.parseInt(temp.substring(i,i+1));
                       N=N+n[i]*list[i];
                   }
                  //System.out.println(N);
                   //N=N+(2*1+1*9);
                   R=N%11;
                  //System.out.println(R);
                // System.out.println(temp.substring(17));
                   switch(R){
                       case 0:T="1";break;
                       case 1:T="0";break;
                       case 2:T="X";break;
                       case 3:T="9";break;
                       case 4:T="8";break;
                       case 5:T="7";break;
                       case 6:T="6";break;
                       case 7:T="5";break;
                       case 8:T="4";break;
                       case 9:T="3";break;
                       case 10:T="2";break;
     }
     //System.out.println(T);
     if(temp.substring(17).equals(T)) {
     t2.setText(temp);
     }
     else {
     Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "身份证号码检验出错!", "错误警告", 
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
     }
     }
     String a0 = temp.substring(0,6);
String a1 = temp.substring(6,10);
String a2 = temp.substring(10,12);
String a3 = temp.substring(12,14);
int s0 = Integer.parseInt(a0);
System.out.print(s0);
int sex1 = Integer.parseInt(temp.substring(14,18));
born = (a1 + "年" + a2 + "月" + a3 + "日");
if(sex1 % 2 == 0) {
sex ="女";
}else{ sex = "男";}
//System.out.println(born);
s2.setText(born);
s3.setText(sex);


try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException ex) {

     Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, ex.getMessage(), "错误警告", 
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
System.exit(-1);
}

try{
String URL = "jdbc:odbc:IDC";
Connection con = DriverManager.getConnection(URL);
if(!con.isClosed()) {
Statement stmt = con.createStatement();
String SQL = "select DQ from IDC where BM ='"+ a0+"'";
ResultSet rs = stmt.executeQuery(SQL);

while(rs.next()) {
addr = rs.getString("DQ");
System.out.println(addr);
}
}else {

     Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "数据库连接失败", "错误警告", 
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
}
con.close();
}catch(SQLException ex) {

     Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, ex.getMessage(), "错误警告", 
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
}



}
}



}
 有意者加我QQ253400833