資源簡介
一個鏈接數據庫的小作品,沒什么技術技巧,僅供志同道合在學習java的同學參考參考

代碼片段和文件信息
package?com.rainplus;
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.SQLException;
import?java.sql.Statement;
import?javax.swing.JButton;
import?javax.swing.Jframe;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
import?javax.swing.JPasswordField;
import?javax.swing.JTextField;
class?Loginframe?extends?Jframe?{
private?JPanel?content;
private?JLabel?userLabel;
private?JLabel?passwordLabel;
private?JPasswordField?passwordField;
private?JTextField?userNameField;
private?JButton?loginButton;
private?JButton?exitButton;
public?Loginframe()?{
super(“學生選課系統“);
setSize(250?200);
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
content?=?new?JPanel();
content.setLayout(null);
add(content);
userLabel?=?new?JLabel(“學號:“);
userLabel.setBounds(30?30?40?20);
content.add(userLabel);
userNameField?=?new?JTextField(“11046208“);
userNameField.setBounds(80?30?120?20);
content.add(userNameField);
passwordLabel?=?new?JLabel(“密碼:“);
passwordLabel.setBounds(30?60?40?20);
content.add(passwordLabel);
passwordField?=?new?JPasswordField();
passwordField.setBounds(80?60?120?20);
content.add(passwordField);
loginButton?=?new?JButton(“登錄“);
loginButton.setBounds(30?100?80?30);
loginButton.addActionListener(new?buttonListenner());
content.add(loginButton);
exitButton?=?new?JButton(“退出“);
exitButton.setBounds(120?100?80?30);
exitButton.addActionListener(new?buttonListenner());
content.add(exitButton);
/*?設置窗體可見和居中?*/
setVisible(true);
setLocationRelativeTo(null);
}
public?static?void?main(String[]?args)?{
new?Loginframe();
}
class?buttonListenner?implements?ActionListener?{
@Override
public?void?actionPerformed(ActionEvent?e)?{
if?(exitButton?==?e.getSource())?{
System.exit(0);
}
if?(loginButton?==?e.getSource())?{
/*?對數據庫的提取驗證操作;?*/
try?{
Class.forName(“com.mysql.jdbc.Driver“);
String?url?=?“jdbc:mysql://localhost/school?user=root&password=root“;
Connection?conection?=?DriverManager.getConnection(url);
Statement?statement?=?conection.createStatement();
String?sql?=?“SELECT?*?FROM?user“;//?選擇用戶表
/*?獲取結果集?*/
ResultSet?resultSet?=?statement.executeQuery(sql);
resultSet.next();
String?userName?=?resultSet.getString(1);
while?(!userName.equals(userNameField.getText()))?{
resultSet.next();
userName?=?resultSet.getString(1);
}
if?(userName.equals(userNameField.getText()))?{
String?password?=?resultSet.getNString(2);
if?(password.equals(new?String(passwordField
.getPassword())))?{
new?Mainframe(userNamestatement);
dispose();
}?else?{
JOptionPane.showMessageDialog(null?“密碼
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????451??2013-10-28?20:38??學生管理系統\.classpath
?????文件????????394??2013-10-22?21:47??學生管理系統\.project
?????文件????????598??2013-10-22?21:47??學生管理系統\.settings\org.eclipse.jdt.core.prefs
?????文件???????2897??2013-10-31?19:30??學生管理系統\bin\com\rainplus\Loginfr
?????文件???????2417??2013-10-31?19:30??學生管理系統\bin\com\rainplus\Loginfr
?????文件????????905??2013-11-01?16:09??學生管理系統\bin\com\rainplus\Mainfr
?????文件???????1173??2013-11-01?16:09??學生管理系統\bin\com\rainplus\Mainfr
?????文件???????1010??2013-11-01?16:09??學生管理系統\bin\com\rainplus\Mainfr
?????文件???????7242??2013-11-01?16:09??學生管理系統\bin\com\rainplus\Mainfr
?????文件???????3240??2013-10-26?16:02??學生管理系統\src\com\rainplus\Loginfr
?????文件???????7063??2013-11-01?16:09??學生管理系統\src\com\rainplus\Mainfr
?????目錄??????????0??2013-10-31?19:30??學生管理系統\bin\com\rainplus
?????目錄??????????0??2013-10-25?15:56??學生管理系統\src\com\rainplus
?????目錄??????????0??2013-10-31?19:30??學生管理系統\bin\com
?????目錄??????????0??2013-10-22?21:53??學生管理系統\src\com
?????目錄??????????0??2013-10-22?21:47??學生管理系統\.settings
?????目錄??????????0??2013-10-31?19:30??學生管理系統\bin
?????目錄??????????0??2013-10-22?21:53??學生管理系統\src
?????目錄??????????0??2013-10-22?21:47??學生管理系統
-----------?---------??----------?-----??----
????????????????27390????????????????????19
評論
共有 條評論