各位高手帮帮忙吧

猛力力 发布于 2013/03/26 15:18
阅读 129
收藏 0
各位高手帮帮忙吧,周四就要交了,我弄了一天了,就是登录界面的程序和数据库里的数据对不上,没法弹出对话框啊,代码如下:
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.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Logininterface extends JFrame implements ActionListener{
JLabel username_l=new JLabel("账号");
     JLabel password_l=new JLabel("密码");
     JButton login_b=new JButton("登录");
     JButton exit_b=new JButton("重置");
     JTextField username_t=new JTextField("",15);
     JTextField password_t=new JTextField("",15);
 public  Logininterface()  //登陆窗口
  {
   this.setTitle("教师工资管理系统");
   this.setLayout(null);
   username_l.setBounds(100,40,100,20);
   this.add(username_l);
   username_t.setBounds(200,40,100,20);
   this.add(username_t);
   password_l.setBounds(100,100,100,20);
   this.add(password_l);
   password_t.setBounds(200,100,100,20);
   this.add(password_t);
   login_b.setBounds(100,150,60,20);
   this.add(login_b);
   //login_b.addActionListener(this);
   exit_b.setBounds(200,150,60,20);
   this.add(exit_b);
   //exit_b.addActionListener(this);
   this.setBounds(400,200,400,250);
   this.setVisible(true);
   }
  public static void main(String[] args) throws Exception {
  // TODO Auto-generated method stub
  new loginFrame();
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //加载驱动程序
  Connection con = DriverManager.getConnection("jdbc:odbc:student"); //取得数据源并进行连接
  Statement st = con.createStatement(); //创建语句
  ResultSet rs = st.executeQuery("SELECT * FROM Login"); //执行查询,得到以行为单位的数据集
  while (rs.next()) { //遍历每行
  //System.out.print(rs.getString("UserName") + "\t");
  //System.out.print(rs.getString("Password") + "\t");
  //System.out.println();
   String UserName=rs.getString(1); //获得数据库第一列
      String Password=rs.getString(2);
      }
  }  @Override
 public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  if(e.getSource()==login_b)
  {
   String t1=username_t.getText();
   String t2=password_t.getText();
      if(UserName.equals(t1)&&Password.equals(t2))
 }
  }
 }
 
加载中
0
秋雨
秋雨
你要做一个登录验证功能?
猛力力
恩恩。就是登录界面连接不上数据库,两边就无法吻合,也就弹不出下一个窗口
0
lock_free
lock_free
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.Statement;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class LoginInterface extends JFrame implements ActionListener {
	JLabel username_l = new JLabel("账号");
	JLabel password_l = new JLabel("密码");
	JButton login_b = new JButton("登录");
	JButton exit_b = new JButton("重置");
	JTextField username_t = new JTextField("", 15);
	JTextField password_t = new JTextField("", 15);

	public LoginInterface() // 登陆窗口
	{
		this.setTitle("教师工资管理系统");
		this.setLayout(null);
		username_l.setBounds(100, 40, 100, 20);
		this.add(username_l);
		username_t.setBounds(200, 40, 100, 20);
		this.add(username_t);
		password_l.setBounds(100, 100, 100, 20);
		this.add(password_l);
		password_t.setBounds(200, 100, 100, 20);
		this.add(password_t);
		login_b.setBounds(100, 150, 60, 20);
		this.add(login_b);
		login_b.addActionListener(this);
		exit_b.setBounds(200, 150, 60, 20);
		this.add(exit_b);
		// exit_b.addActionListener(this);
		this.setBounds(400, 200, 400, 250);
		this.setVisible(true);
	}

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		new LoginInterface();
		
	}

	private boolean isValid(String user, String password) {

		//此处用jdbc 运行"SELECT count(*) FROM Login where userName=? and password= ?"
		// 判断 result size.
		return true;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getSource() == login_b) {
			String t1 = username_t.getText();
			String t2 = password_t.getText();
			if (isValid(t1, t2)) {
				this.setVisible(false);
				SuccessFrame frame = new SuccessFrame();
				frame.setVisible(true);
			}
		}
	}
}
import javax.swing.JFrame;
import javax.swing.JLabel;

public class SuccessFrame extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7242096340424415373L;
	JLabel label=new JLabel();
	public SuccessFrame(){
		this.setLayout(null);
		label.setText("ok----------");
		label.setBounds(100, 100, 100, 20);
		this.add(label);
		this.setBounds(400, 200, 400, 250);
	}
}
猛力力
select那里是我连接数据库的,但是感觉就是错的,但你改的也不对吧,我要调用数据库里的东西啊,亲貌似给整到JSP上了,我是用JAVA做这个的
返回顶部
顶部