package 医院;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
public class NewJFrame extends javax.swing.JFrame implements ActionListener{ {
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
}
} private JLabel title;
private JPasswordField jPasswordField1;
private JButton submit;
private JTextField jTextField1;
private JLabel password;
private JLabel name;
private String myname;
private String mypassword;
Connection conn;
Statement stmt; /**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}

public NewJFrame() {
super();
initGUI();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// String dburl
// ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=hjh.mdb";//此为NO-DSN方式
String dburl = "jdbc:odbc:hejinghong";// 此为ODBC连接方式
conn = DriverManager.getConnection(dburl);
stmt = conn.createStatement();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
title = new JLabel();
getContentPane().add(title);
title.setText("\u533b\u9662\u767b\u5f55");
title.setBounds(165, 44, 48, 15);
}
{
name = new JLabel();
getContentPane().add(name);
name.setText("\u7528\u6237\u540d\uff1a");
name.setBounds(107, 91, 51, 15);
}
{
password = new JLabel();
getContentPane().add(password);
password.setText("\u5bc6\u7801\uff1a");
password.setBounds(119, 126, 39, 15);
}
{
jTextField1 = new JTextField();
getContentPane().add(jTextField1);
jTextField1.setBounds(158, 88, 96, 21);
}
{
jPasswordField1 = new JPasswordField();
getContentPane().add(jPasswordField1);
jPasswordField1.setBounds(158, 123, 96, 21);
}
{
submit = new JButton();
submit.addActionListener(this);
getContentPane().add(submit);
submit.setText("\u767b\u5f55");
submit.setBounds(254, 197, 57, 23);
}
pack();
setSize(400, 300);
} catch (Exception e) {
    //add your error handling code here
e.printStackTrace();
}
}

// public void link() throws Exception{





//} @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == submit){

String   myname = jTextField1.getText().trim();
   String mypassword = jPasswordField1.getText();

System.out.println(myname+"\n"+mypassword);

ResultSet rs1 = null;

//ResultSet rs2= null;
try {
  rs1=stmt.executeQuery("select no from student where student.no = '"+myname+"'"  +"and  student.name = '"+mypassword+"'");
// rs2=ResultSet rs = null;("Select *from student");
  //rs2 =stmt.executeQuery("select no from student where student.name = '"+mypassword+"'");
if (rs1.next()) {
//if(myname.equals(rs2.getString(1))){
System.out.println("登录成功");
}else{
System.out.println("登录失败");
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally{
try {
rs1.close();

stmt.close();
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

}

}
}}