请老兄 帮忙 解救
下面是我的一个登陆框,在JBuilder 里运行是输入 sa,密码:sa, 后 成功登陆,可登陆时,总是出“error",try中的语言就没执行,请朋友们帮帮忙,小弟是现学现做,根本看不出问题!!谢谢!
package benchang;
import javax.swing.JFrame;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import benchang.Frame1;
import javax.swing.JOptionPane;
import java.sql.SQLException;
import java.sql.ResultSet;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008 </p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Frame3 extends JFrame {
private String url =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=chang;integratedSecurity=true;";
private Connection conn;
private Statement stmt;
private ResultSet rs;
Frame1 frame = new Frame1();
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
XYLayout xYLayout2 = new XYLayout();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public Frame3() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setBounds(100,100,450,400);
getContentPane().setLayout(xYLayout1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
jPanel1.setMinimumSize(new Dimension(450, 330));
xYLayout1.setWidth(434);
xYLayout1.setHeight(338);
jButton2.addActionListener(new Frame3_jButton2_actionAdapter(this));
jButton1.addActionListener(new Frame3_jButton1_actionAdapter(this));
this.getContentPane().add(jPanel1, new XYConstraints(0, 0, 423, 330));
jPanel1.setLayout(xYLayout2);
jLabel2.setText("用户名:");
jLabel3.setText("密 码:");
jButton1.setText("登陆");
jButton2.setText("退出");
jPanel1.add(jLabel1, new XYConstraints(190, 5, 78, 29));
jPanel1.add(jLabel2, new XYConstraints(52, 85, 58, 31));
jPanel1.add(jLabel3, new XYConstraints(51, 165, 59, 30));
jPanel1.add(jTextField1, new XYConstraints(230, 92, 88, 25));
jPanel1.add(jButton1, new XYConstraints(51, 258, -1, -1));
jPanel1.add(jButton2, new XYConstraints(249, 258, -1, -1));
jPanel1.add(jPasswordField1, new XYConstraints(230, 165, 88, -1));
jLabel1.setText("用户登陆");
}
public static void main(String[] args) {
Frame3 frame3 = new Frame3();
}
public void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
public void jButton1_actionPerformed(ActionEvent e) {
try {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException ex) {
}
String yh = jTextField1.getText();
String ps = jPasswordField1.toString();
String sql =
"select * from yonghu where dzid="+yh+"and pswd="+ps+"";
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
int rows=rs.getRow();
if (rows==1){
this.frame.setVisible(false);
frame.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
System.exit(0);
}
} catch (SQLException sqException) {
JOptionPane.showMessageDialog(null, "ERROR");
}
}
}
class Frame3_jButton1_actionAdapter implements ActionListener {
private Frame3 adaptee;
Frame3_jButton1_actionAdapter(Frame3 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Frame3_jButton2_actionAdapter implements ActionListener {
private Frame3 adaptee;
Frame3_jButton2_actionAdapter(Frame3 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}