⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginframe.java

📁 在eclipse开发环境下使用java变成语言连接Mysql,读取数据
💻 JAVA
字号:
package verity;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.print.DocFlavor.STRING;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

import java.awt.GridLayout;
import java.sql.*;

public class LoginFrame extends JFrame implements ActionListener{

    JLabel label =new JLabel("用户明和密码");
    JTextField tfname=new JTextField("");
    JPasswordField tfpassword=new JPasswordField("");
    JButton button=new JButton("login");
    public LoginFrame(){
	this.setTitle("verfy login");
	button.addActionListener(this);
	this.getContentPane().setLayout(new GridLayout(4,1));
	this.getContentPane().add(label);
	this.getContentPane().add(tfname);
	this.getContentPane().add(tfpassword);
	this.getContentPane().add(button);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	this.setSize(300,200);
	this.setLocation(200,300);
	this.setVisible(true);
    }
    public void actionPerformed(ActionEvent arg0) {
	try{
	    Class.forName("org.gjt.mm.mysql.Driver");
	    java.sql.Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","root");
	    java.sql.Statement stmt=conn.createStatement();
	    String sql="select* from account where username='"+tfname.getText()+"'";
	    sql+="and password='"+tfpassword.getText()+"'";
	    ResultSet rs=stmt.executeQuery(sql);
	    if(rs.next())
		label.setText("hefa");
	    else
		label.setText("no");
	}catch(Exception ee){
	    ee.printStackTrace();
	}
	
    }
    public static void main(String[] args){
	new LoginFrame();
    }
    

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -