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

📄 landtest.java

📁 实现连接数据库登录表 主要是MYSQL数据库
💻 JAVA
字号:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import com.mysql.jdbc.Driver;
/**
 * @author  yeeku.H.lee kongyeeku@163.com
 * @version  1.0
 * <br>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br>This program is protected by copyright laws.
 * <br>Program Name:
 * <br>Date: 
 */
public class LandTest 
{
	JFrame f = new JFrame();
	JButton jb1 = new JButton("登陆");
	JButton jb2 = new JButton("退出");
	JLabel name = new JLabel("姓名");
	JLabel pass = new JLabel("密码");
	JTextField nametext = new JTextField(20);
	JTextField passtext = new JTextField(20);
	public void show()
	{
		JPanel jp = new JPanel(new GridLayout(3,3));
		jp.add(name);
		jp.add(nametext);
		jp.add(pass);
		jp.add(passtext);
		jp.add(jb1);
		jp.add(jb2);
		jb1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				try
				{
					Class.forName("com.mysql.jdbc.Driver");
					Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mm","root","111111");
					Statement stat = con.createStatement();
					String nt = nametext.getText();
					String pt = passtext.getText();
					if (nt.length()==0||pt.length()==0)
					{
						JOptionPane.showMessageDialog(f,"用户名或密码不能为空","系统消息",JOptionPane.ERROR_MESSAGE);
						return;
					}
					else{
					ResultSet res = stat.executeQuery("select * from land_table where stu_name = '"+nt+"'and stu_pass = '"+pt+"';");
					if (res.next())
					{
						
						JOptionPane.showMessageDialog(f,"登陆成功","系统消息",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
						JOptionPane.showMessageDialog(f,"用户名或密码错误","系统消息",JOptionPane.ERROR_MESSAGE);
					}}
				}
				catch (Exception ex)
				{
					JOptionPane.showMessageDialog(f,ex.getMessage());
					ex.printStackTrace();
				}
				
			}
		});
		jb2.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.exit(0);
			}
		});
		f.add(jp);
		f.pack();
		f.setVisible(true);
	}
    public static void main(String[] args) 
    {
        new LandTest().show();
    }
}

⌨️ 快捷键说明

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