📄 student_information.java
字号:
package coursedesign;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.borland.dbswing.JdbTable;
import com.borland.dbswing.JdbStatusLabel;
import com.borland.dbswing.JdbNavToolBar;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.dataset.DataSetView;
import com.borland.datastore.DataStore;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.QueryResolver;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dbswing.JdbTextField;
import com.borland.dbswing.TableScrollPane;
import com.borland.dbswing.JdbList;
import com.borland.dbswing.JdbSlider;
import com.borland.dbswing.JdbEditorPane;
import com.borland.dbswing.JdbLabel;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Student_Information
extends JFrame {
JButton jButton1 = new JButton();
XYLayout xYLayout1 = new XYLayout();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JdbTable jdbTable1 = new JdbTable();
JdbNavToolBar jdbNavToolBar1 = new JdbNavToolBar();
Database student = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryResolver queryResolver1 = new QueryResolver();
JdbTextField jdbTextField1 = new JdbTextField();
JdbTextField jdbTextField2 = new JdbTextField();
JdbTextField jdbTextField3 = new JdbTextField();
JdbTextField jdbTextField4 = new JdbTextField();
JdbTextField jdbTextField5 = new JdbTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JButton jButton5 = new JButton();
public Student_Information() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
this.getContentPane().setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleForeground"));
setSize(new Dimension(500, 400));
setTitle("学生信息");
jButton1.setText("退出");
jButton1.addActionListener(new Student_Information_jButton1_actionAdapter(this));
jButton2.setToolTipText("");
jButton2.setAction(null);
jButton2.setActionCommand("添加");
jButton2.setText("添加");
jButton2.addActionListener(new Student_Information_jButton2_actionAdapter(this));
jButton3.setText("修改");
jButton3.addActionListener(new Student_Information_jButton3_actionAdapter(this));
jButton4.setText("删除");
jButton4.addActionListener(new Student_Information_jButton4_actionAdapter(this));
student.setConnection(new ConnectionDescriptor(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student", "sa",
"zjxy2006", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver",
ConnectionDescriptor.arrayToProperties(new String[][] { {"serverName",
""}, {"hostProcess", ""},
{"user", "sa"}, {"netAddress",
""},
{"sendStringParametersAsUnicode ",
"true"}, {"programName", ""},
{"databaseName", "student"},
{"selectMethod", "direct"},
{"password", "zjxy2006"},
{"portNumber", "1433"},
})));
queryDataSet1.setReadOnly(true);
queryDataSet1.setResolver(queryResolver1);
queryDataSet1.setQuery(new QueryDescriptor(student,
"select * from base_info", null, true,
Load.ALL));
queryResolver1.setDatabase(student);
queryResolver1.setUpdateMode(com.borland.dx.dataset.UpdateMode.
CHANGED_COLUMNS);
jdbTable1.setDataSet(queryDataSet1);
jdbNavToolBar1.setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleForeground"));
jdbNavToolBar1.setDataSet(queryDataSet1);
jdbTextField1.setHorizontalAlignment(SwingConstants.RIGHT);
jdbTextField1.setColumnName("id");
jdbTextField1.setDataSet(queryDataSet1);
jdbTextField2.setHorizontalAlignment(SwingConstants.RIGHT);
jdbTextField2.setColumnName("name");
jdbTextField2.setDataSet(queryDataSet1);
jdbTextField4.setHorizontalAlignment(SwingConstants.RIGHT);
jdbTextField4.setColumnName("class");
jdbTextField4.setDataSet(queryDataSet1);
jdbTextField4.addActionListener(new
Student_Information_jdbTextField4_actionAdapter(this));
jdbTextField3.setColumnName("sex");
jdbTextField3.setDataSet(queryDataSet1);
jdbTextField5.setHorizontalAlignment(SwingConstants.RIGHT);
jdbTextField5.setColumnName("address");
jdbTextField5.setDataSet(queryDataSet1);
jLabel1.setText("学号:");
jLabel2.setText("姓名:");
jLabel3.setText("班级:");
jLabel5.setText("地址:");
jLabel4.setText("性别:");
jLabel6.setText("学号:");
jLabel7.setText("姓名:");
jButton5.setText("查询");
jButton5.addActionListener(new Student_Information_jButton5_actionAdapter(this));
this.getContentPane().add(jButton3, new XYConstraints(125, 19, 57, 23));
this.getContentPane().add(jButton4, new XYConstraints(230, 19, 57, 23));
this.getContentPane().add(jButton1, new XYConstraints(328, 19, 69, -1));
this.getContentPane().add(jdbTextField3, new XYConstraints(79, 343, 88, -1));
this.getContentPane().add(jLabel4, new XYConstraints(21, 345, -1, -1));
this.getContentPane().add(jLabel5, new XYConstraints(180, 349, -1, -1));
this.getContentPane().add(jButton2, new XYConstraints(20, 19, 63, -1));
this.getContentPane().add(jdbTextField2, new XYConstraints(233, 303, 83, -1));
this.getContentPane().add(jdbTable1, new XYConstraints(0, 182, 500, 100));
this.getContentPane().add(jdbTextField1, new XYConstraints(69, 303, 91, -1));
this.getContentPane().add(jLabel1, new XYConstraints(19, 306, 43, -1));
this.getContentPane().add(jLabel3, new XYConstraints(346, 306, 44, -1));
this.getContentPane().add(jdbTextField4, new XYConstraints(393, 303, 84, -1));
this.getContentPane().add(jLabel2, new XYConstraints(178, 306, 40, -1));
this.getContentPane().add(jdbTextField5, new XYConstraints(235, 344, 72, -1));
this.getContentPane().add(jdbNavToolBar1,
new XYConstraints( -9, 141, 497, -1));
this.getContentPane().add(jLabel6, new XYConstraints(16, 100, -1, -1));
this.getContentPane().add(jTextField1, new XYConstraints(87, 94, 76, -1));
this.getContentPane().add(jLabel7, new XYConstraints(191, 99, -1, -1));
this.getContentPane().add(jTextField2, new XYConstraints(259, 95, 78, -1));
this.getContentPane().add(jButton5, new XYConstraints(389, 92, -1, -1));
}
public void jButton1_actionPerformed(ActionEvent e) {
dispose();
}
//***************************添加学生信息*********************************
public void jButton2_actionPerformed(ActionEvent actionEvent) {
String input1 = JOptionPane.showInputDialog("请输入学号:");
String input2 = JOptionPane.showInputDialog("请输入姓名:");
String input3 = JOptionPane.showInputDialog("请输入班级:");
String input4 = JOptionPane.showInputDialog("请输入性别:");
String input5 = JOptionPane.showInputDialog("请输入家庭地址:");
try {
Jdbcconn conn = new Jdbcconn();
//连接数据库
conn.OpenConn("student", "sa", "zjxy2006");
String strSQL =
"insert into base_info (id,name,class,sex,address) values ('" + input1 +
"','" + input2 + "','" + input3 + "','" + input4 + "','" + input5 +
"')";
conn.executeUpdate(strSQL);
//refreshComponent();
queryDataSet1.refresh();//有必要加哦,否则表格里不会显加新加的信息
JOptionPane.showMessageDialog(null, "添加成功");
//System.out.println("name");
}
catch (Exception ex) {
System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(null, "数据库没有链接成功,数据没有输入成功!");
}
}
public void jdbTextField4_actionPerformed(ActionEvent e) {
}
//**********************************查询学生基本信息*************************
public void jButton5_actionPerformed(ActionEvent e) {
String Field1 = jTextField1.getText().trim();
String Field2 = jTextField2.getText().trim();
if (Field1.equals("") || Field2.equals("")) {
try {
JOptionPane.showMessageDialog(null, "学号或姓名为空,不能查询!");
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
} //end if
else {
try {
String sql = "select * from chengjibiao where id='" + Field1 + "'";
queryDataSet1.close();
//将SQL语句传给queryDataSet1执行。
queryDataSet1.setQuery(new QueryDescriptor(student, sql, null, true,
Load.ALL));
//将queryDataSet1打开
queryDataSet1.open();
//刷新queryDataSet1
queryDataSet1.refresh();
} //end try
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Sorry!成绩都已经输入");
} //end catch
} //end else
} //此事件完成
//******************************修改学生信息*************************
public void jButton3_actionPerformed(ActionEvent e) {
String id = jdbTextField1.getText().trim();
String Field2 = jdbTextField2.getText().trim();
String Field3 = jdbTextField1.getText().trim();
String Field4 = jdbTextField2.getText().trim();
String Field5 = jdbTextField1.getText().trim();
String strSQL;
try {
Jdbcconn conn = new Jdbcconn();
//连接数据库
conn.OpenConn("student", "sa", "zjxy2006");
strSQL = "update base_info set name='" + Field2 + "',class='" + Field3 +
"',sex='" + Field4 + "',address='" + Field5 + "' where id='" +
id + "'";
conn.executeUpdate(strSQL);
JOptionPane.showMessageDialog(null, "修改成功");
//System.out.print("修改成功"+strSQL);
queryDataSet1.refresh();
}
catch (Exception ex) {
System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(null, "数据库没有链接成功,数据没有修改成功!");
} //end catch
}
public static void main(String as[]){
Student_Information dd=new Student_Information();
dd.setVisible(true);
dd.setLocationRelativeTo(null);
}
//****************************删除学生信息******************************
public void jButton4_actionPerformed(ActionEvent e) {
String input1=JOptionPane.showInputDialog("请输入要删除的学生号学号");
String input2=JOptionPane.showInputDialog("请输入要删除的学生号姓名");
if(input1.equals("")||input2.equals(""))
{
JOptionPane.showMessageDialog(null, "你必须输入学号和姓名才能删除");
}else{
Jdbcconn conn = new Jdbcconn();
//连接数据库
try {
conn.OpenConn("student", "sa", "zjxy2006");
String strSQL = "delete from base_info where id='" + input1 +
"' and name='" + input2 + "'";
conn.executeUpdate(strSQL);
queryDataSet1.refresh();
JOptionPane.showMessageDialog(null, "删除成功");
//System.out.println("name");
}
catch (Exception ex) {
System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(null, "数据库没有链接成功,数据没有修改成功!");
} //end catch
}
}
}//end class
class Student_Information_jButton4_actionAdapter
implements ActionListener {
private Student_Information adaptee;
Student_Information_jButton4_actionAdapter(Student_Information adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class Student_Information_jButton3_actionAdapter
implements ActionListener {
private Student_Information adaptee;
Student_Information_jButton3_actionAdapter(Student_Information adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class Student_Information_jButton5_actionAdapter
implements ActionListener {
private Student_Information adaptee;
Student_Information_jButton5_actionAdapter(Student_Information adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}
class Student_Information_jdbTextField4_actionAdapter
implements ActionListener {
private Student_Information adaptee;
Student_Information_jdbTextField4_actionAdapter(Student_Information adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jdbTextField4_actionPerformed(e);
}
}
class Student_Information_jButton2_actionAdapter
implements ActionListener {
private Student_Information adaptee;
Student_Information_jButton2_actionAdapter(Student_Information adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jButton2_actionPerformed(actionEvent);
}
}
class Student_Information_jButton1_actionAdapter
implements ActionListener {
private Student_Information adaptee;
Student_Information_jButton1_actionAdapter(Student_Information adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -