//数据连接类:
package com.scjh;import java.sql.*;
public class DataConnection implements LoginInterface {
private Connection conn;     
    private PreparedStatement pstmt ;
    private Statement stmt;
    ResultSet rs;
    
    public  DataConnection(){
        
    }

    public Connection getConnection() {
    
     String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
     String url = "jdbc:microsoft:sqlserver://localhost:1433;databasename=scjh";
     String user = "sa";
     String password = "sa";
 try{
        Class.forName(driver);
     conn = DriverManager.getConnection(url, user, password);
     if(conn==null)
          throw  new Exception("在创建数据库连接失败\nClas名称:");
        }catch(Exception e)
  {
 System.out.println(e.getMessage());
 }
   return  conn;
     }     public Statement  getStatement() throws Exception{
      String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
      String url = "jdbc:microsoft:sqlserver://localhost:1433;databasename=scjh";
      String user = "sa";
      String password = "sa";
     
         Class.forName(driver);
if(stmt==null){
     Connection  conn = DriverManager.getConnection(url,user,password);
     if(conn==null)
          throw  new Exception("在创建数据库连接失败\nClas名称:");
          stmt = conn.createStatement();
     if(stmt==null)
        throw  new Exception("在创建Statement失败\nClas名称:");
   }
   return  stmt;
      }
     
      public ResultSet executeQuery(String sql){
       stmt = null;
       rs = null;
       try{
       stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
       rs = stmt.executeQuery(sql);
       }
       catch(SQLException e){
       System.err.println("executeQuery:"+e.getMessage());
       }
return rs;
      }
      
      public ResultSet executeUpdate(String sql){
       stmt = null;
       rs = null;
       try{
       stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = stmt.executeQuery(sql);
        conn.commit();
       }
       catch(SQLException e){
       System.err.println("executeUpdate:"+e.getMessage());
       }
return rs;
      }
      
      public ResultSet execute(String sql){
       stmt = null;
       rs = null;
       try{
       stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
       rs = stmt.executeQuery(sql);
       }
       catch(SQLException e){
       System.err.println("executeQuery:"+e.getMessage());
       }
return rs;
      }
      
      public void closeStmt(){
       try{
       stmt.close();
       }
       catch(SQLException e){
       System.err.println("closStmt:"+e.getMessage());
       }
      }
     
  public void closeConn()
 { 
  try{
  conn.close();
  
  }catch(SQLException ex){
  System.err.println("closConn:"+ex.getMessage()); 
  }

  }
    
}
//这是一个LoginBEAN
package com.scjh;import java.sql.*;
import javax.swing.*;public class LoginBean {
   
private String ID;
private JPasswordField password;

public void Login(String nID,JPasswordField tf2){

DataConnection dc = new DataConnection();

this.ID = nID;
this.password = tf2;

if(tf2.equals("")){
JOptionPane.showMessageDialog(null,"密码不能为空");
return;
}
else{
String sql = "select * from login where ID='"+nID+"' and password='"+tf2.getText()+"'";
Connection conn = dc.getConnection();
try{
Statement cmd = conn.createStatement(); 
    ResultSet rs=cmd.executeQuery(sql);
    
    if(rs.next()){
     JOptionPane.showMessageDialog(null,"登录成功");
    }
    else 
     JOptionPane.showMessageDialog(null,"密码错误,请重试!");
 }
catch(SQLException e){
e.printStackTrace();
}
}

}//Login
public void LoginBean(){

}


public String getID() {
return ID;
} public void setID(String id) {
this.ID = id;
} public JPasswordField getPassword() {
return password;
} public void setPassword(JPasswordField string) {
this.password = string;
}

}
//窗体代码:
package com.scjh;import javax.swing.*;//import com.sun.corba.se.pept.transport.Connection;
import java.awt.*;
import java.awt.event.*;
//mport java.sql.PreparedStatement;
import java.sql.*;public class LoginFra extends javax.swing.JFrame {

JButton jb1 = new JButton("确定");
JButton jb2 = new JButton("取消");

//TextField tf1 = new TextField(30);
JPasswordField  tf = new JPasswordField (30);



JLabel jl1 = new JLabel("请选择权限登录:",JLabel.CENTER);
JLabel jl2 = new JLabel("密码:",JLabel.CENTER);
//JLabel jl3 = new JLabel("请选择权限登录:",JLabel.CENTER);

Choice c = new Choice();
String description[] = {"管理员","订单管理员","物料需求管理员","生产部门管理员","采购管理员","销售管理员","库存管理员"};

String sql;
ResultSet rs ;
DataConnection  db = new DataConnection(); 
//ResultSet rs;
Connection conn= db.getConnection();
Statement stmt ;
PreparedStatement pstmt;

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {

LoginFra inst = new LoginFra();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}//main()

public LoginFra() {
super();
initGUI();
}//LoginFra()



private void initGUI() {
try {

setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
pack();
setSize(400, 300);
setTitle("登录窗体");
setLayout(new GridLayout(3,2));

for(int i=0;i<7;i++)
{c.addItem(description[i]);}

    add(jl1);add(c);add(jl2);add(tf);
add(jb1);add(jb2);

jb1.addActionListener(new CL());
jb2.addActionListener(new CL());
//c.addItemListener((ItemListener) new CL());

} catch (Exception e) {
e.printStackTrace();
}
}//initGUI()
   
class CL implements ActionListener{

public void actionPerformed(ActionEvent e){



if (e.getSource()== jb1&& e.getSource()==c.getItem(0)){

LoginBean lb = new LoginBean();
lb.Login(c.getSelectedItem(), tf);
ResearchFra rf = new ResearchFra();
rf.setVisible(true);

//dispose();

}//if
else if (e.getSource() == jb2){

//tf1.setText(""); 
tf.setText(""); 
}
 
}//actionPerform
}//class CL}//class LoginFra我的问题是:编译窗体代码时没有抛出异常,但也没有执行这个ResearchFra rf = new ResearchFra();rf.setVisible(true);这到底是什么回事呀?还有我的窗体代码中,密码的输入的方框是JpasswordField,这会不会受到影响了.