//這個(gè)是我寫(xiě)的,里面有連接數(shù)據(jù)庫(kù)的部分。你可以拿去參考一下
創(chuàng)新互聯(lián)是一家專業(yè)提供蘆淞企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、做網(wǎng)站、H5建站、小程序制作等業(yè)務(wù)。10年已為蘆淞眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class LoginFrm extends JFrame implements ActionListener// throws Exception
{
JLabel lbl1 = new JLabel("用戶名:");
JLabel lbl2 = new JLabel("密碼:");
JTextField txt = new JTextField(5);
JPasswordField pf = new JPasswordField();
JButton btn1 = new JButton("確定");
JButton btn2 = new JButton("取消");
public LoginFrm() {
this.setTitle("登陸");
JPanel jp = (JPanel) this.getContentPane();
jp.setLayout(new GridLayout(3, 2, 5, 5));
jp.add(lbl1);
jp.add(txt);
jp.add(lbl2);
jp.add(pf);
jp.add(btn1);
jp.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == btn1) {
try {
Class.forName("com.mysql.jdbc.Driver");// mysql數(shù)據(jù)庫(kù)
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/Car_zl", "root", "1");// 數(shù)據(jù)庫(kù)名為Car_zl,密碼為1
System.out.println("com : "+ con);
Statement cmd = con.createStatement();
String sql = "select * from user where User_ID='"
+ txt.getText() + "' and User_ps='"
+ pf.getText() + "'" ;
ResultSet rs = cmd
.executeQuery(sql);// 表名為user,user_ID和User_ps是存放用戶名和密碼的字段名
if (rs.next()) {
JOptionPane.showMessageDialog(null, "登陸成功!");
} else
JOptionPane.showMessageDialog(null, "用戶名或密碼錯(cuò)誤!");
} catch (Exception ex) {
}
if (ae.getSource() == btn2) {
System.out.println("1111111111111");
//txt.setText("");
//pf.setText("");
System.exit(0);
}
}
}
public static void main(String arg[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
LoginFrm frm = new LoginFrm();
frm.setSize(400, 200);
frm.setVisible(true);
}
}
性能測(cè)試中示例代碼使用java批量注冊(cè)登錄賬戶。
性能測(cè)試過(guò)程中所需的測(cè)試數(shù)據(jù),以登錄為例,為了更真實(shí)的模 批量讀取注冊(cè)。
Java登錄注冊(cè)功能實(shí)現(xiàn)代碼解析,文中通示例代碼,每個(gè)用戶信息都是唯一的,所以可以借助Set的特性來(lái)操作用戶信息的存放。
import?java.util.Scanner;
public?class?Register
{
private?String?username;
private?String?password;
public?Register?(?String?username,?String?password?)
{
this.username?=?username;
this.password?=?password;
}
public?boolean?verfiy?()
{
return?username.length?()?=?3??password.length?()?=?6;
}
public?static?void?main?(?String[]?args?)
{
Scanner?scanner?=?new?Scanner?(System.in);
System.out.println?("輸入用戶名:");
String?username?=?scanner.nextLine?();
System.out.println?("輸入密碼:");
String?password?=?scanner.nextLine?();
scanner.close?();
Register?register?=?new?Register?(username,?password);
if?(register.verfiy?())
{
System.out.println?("合法");
}
else
{
System.out.println?("非法");
}
}
}
網(wǎng)站題目:java代碼實(shí)現(xiàn)注冊(cè) java注冊(cè)機(jī)代碼
URL網(wǎng)址:http://jinyejixie.com/article48/doohhhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷推廣、搜索引擎優(yōu)化、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站排名、網(wǎng)站建設(shè)、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)