?? xiugaichengji.java~23~
字號:
package coursedesign;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import com.borland.dbswing.JdbTable;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dx.sql.dataset.QueryResolver;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.borland.dbswing.JdbTextField;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class xiugaichengji
extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JButton jButton1 = new JButton();
JLabel jLabel3 = new JLabel();
JTextField jTextField2 = new JTextField();
JdbTable jdbTable1 = new JdbTable();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryResolver queryResolver1 = new QueryResolver();
JdbTextField jdbTextField1 = new JdbTextField();
JdbTextField jdbTextField2 = new JdbTextField();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JButton jButton2 = new JButton();
JLabel jLabel6 = new JLabel();
JButton jButton3 = new JButton();
public xiugaichengji() {
try {
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 xiugaichengji_jButton1_actionAdapter(this));
jLabel2.setText("學號");
jLabel3.setText("課程");
queryResolver1.setDatabase(database1);
queryResolver1.setUpdateMode(com.borland.dx.dataset.UpdateMode.
CHANGED_COLUMNS);
queryDataSet1.setResolver(queryResolver1);
jdbTable1.setDataSet(queryDataSet1);
jLabel1.setFont(new java.awt.Font("楷體_GB2312", Font.PLAIN, 20));
jLabel4.setText("課程");
jLabel5.setText("成績");
jdbTextField1.setColumnName("course_name");
jdbTextField1.setDataSet(queryDataSet1);
jdbTextField2.setColumnName("result");
jdbTextField2.setDataSet(queryDataSet1);
jButton2.setText("提交");
jButton2.addActionListener(new xiugaichengji_jButton2_actionAdapter(this));
jLabel6.setFont(new java.awt.Font("楷體_GB2312", Font.PLAIN, 20));
jLabel6.setText("請在下面的框內容輸入你要修改的:");
queryDataSet1.setQuery(new QueryDescriptor(database1,
"SELECT * FROM XUANKEBIAO", null, true,
Load.ALL));
database1.setConnection(new ConnectionDescriptor(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student", "sa",
"yaya", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
jLabel1.setText("請輸入你要修改的學生的學號和課程名");
jButton3.setText("返回所有記錄");
jButton3.addActionListener(new xiugaichengji_jButton3_actionAdapter(this));
this.getContentPane().add(jLabel1, new XYConstraints(19, 9, 364, -1));
this.getContentPane().add(jLabel4, new XYConstraints(11, 301, -1, -1));
this.getContentPane().add(jdbTextField1, new XYConstraints(77, 298, 92, -1));
this.getContentPane().add(jLabel5, new XYConstraints(206, 303, -1, -1));
this.getContentPane().add(jdbTextField2, new XYConstraints(268, 298, 86, 22));
this.getContentPane().add(jButton2, new XYConstraints(396, 294, -1, -1));
this.getContentPane().add(jLabel6, new XYConstraints(6, 244, 416, 31));
this.getContentPane().add(jdbTable1, new XYConstraints(1, 119, 500, 98));
this.getContentPane().add(jLabel2, new XYConstraints(17, 66, -1, -1));
this.getContentPane().add(jTextField1, new XYConstraints(49, 64, 69, -1));
this.getContentPane().add(jLabel3, new XYConstraints(138, 68, -1, -1));
this.getContentPane().add(jTextField2, new XYConstraints(186, 64, 72, -1));
this.getContentPane().add(jButton1, new XYConstraints(296, 61, -1, -1));
this.getContentPane().add(jButton3, new XYConstraints(383, 61, -1, -1));
//jLabel7.setIcon(b);
}
public static void main(String[] args) {
xiugaichengji xiugaichengji = new xiugaichengji();
}
//*************************查找要修改成績的學生信息********************
public void jButton1_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 xuankebiao where id='" + Field1 +
"' or course_name='" + Field2 + "'";
queryDataSet1.close();
//將SQL語句傳給queryDataSet1執行。
queryDataSet1.setQuery(new QueryDescriptor(database1, sql, null, true,
Load.ALL));
queryDataSet1.open(); //將queryDataSet1打開
queryDataSet1.refresh(); //刷新queryDataSet1
} //end try
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Sorry!沒有你要的信息,請檢查你輸入的信息!");
} //end catch
} //end else
}
//********************************修改成績****************************
public void jButton2_actionPerformed(ActionEvent e) {
String Field1 = jdbTextField1.getText().trim();
String Field2 = jdbTextField2.getText().trim();
try {
Jdbcconn conn = new Jdbcconn(); //連接數據庫
conn.OpenConn("student", "sa", "yaya");
String strSQL =
"update xuankebiao set course_name='Field1' ,result='Field2'";
conn.executeUpdate(strSQL);
JOptionPane.showMessageDialog(null, "修改成功");
}
catch (Exception ex) {
System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(null, "數據庫沒有鏈接成功,數據沒有修改成功!");
} //end catch
}
//********************************返回所有記錄****************************
public void jButton3_actionPerformed(ActionEvent e) {
String sql = "select * from xuankebiao";
try {
queryDataSet1.close();
//將SQL語句傳給queryDataSet1執行。
queryDataSet1.setQuery(new QueryDescriptor(database1, sql, null, true,
Load.ALL));
queryDataSet1.open();
queryDataSet1.refresh();
} //end try
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Sorry!返回出現錯誤!");
} //end catch
}
}
class xiugaichengji_jButton3_actionAdapter
implements ActionListener {
private xiugaichengji adaptee;
xiugaichengji_jButton3_actionAdapter(xiugaichengji adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class xiugaichengji_jButton2_actionAdapter
implements ActionListener {
private xiugaichengji adaptee;
xiugaichengji_jButton2_actionAdapter(xiugaichengji adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class xiugaichengji_jButton1_actionAdapter
implements ActionListener {
private xiugaichengji adaptee;
xiugaichengji_jButton1_actionAdapter(xiugaichengji adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -