?? chaxunchengji.java
字號(hào):
package coursedesign;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.QueryResolver;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dbswing.JdbTable;
import java.util.ResourceBundle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
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 chaxunchengji
extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JLabel jLabel1 = new JLabel();
JdbTable jdbTable1 = new JdbTable();
ResourceBundle sqlRes = ResourceBundle.getBundle("coursedesign.SqlRes");
JButton jButton1 = new JButton();
String username;
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
JButton jButton2 = new JButton();
JTextField jTextField2 = new JTextField();
public chaxunchengji() {
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("查詢(xún)成績(jī)");
jButton1.setText("查詢(xún)");
jButton1.addActionListener(new chaxunchengji_jButton1_actionAdapter(this));
xYLayout1.setWidth(499);
xYLayout1.setHeight(398);
database1.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", ""}, {"portNumber",
"1433"},
})));
queryDataSet1.setQuery(new QueryDescriptor(database1,
"select * from chengjibiao where id=\'0000\'", null, true, Load.ALL));
jdbTable1.setDataSet(queryDataSet1);
jButton2.setText("計(jì)算平均分");
jButton2.addActionListener(new chaxunchengji_jButton2_actionAdapter(this));
this.getContentPane().add(jLabel1, new XYConstraints(23, 22, -1, -1));
this.getContentPane().add(jTextField1, new XYConstraints(93, 20, 88, -1));
this.getContentPane().add(jButton1, new XYConstraints(227, 17, -1, -1));
this.getContentPane().add(jdbTable1, new XYConstraints( -1, 73, 498, 152));
this.getContentPane().add(jButton2, new XYConstraints(49, 285, -1, -1));
this.getContentPane().add(jTextField2, new XYConstraints(174, 285, 97, -1));
jLabel1.setText("學(xué)號(hào)");
//Icon b =new ImageIcon("13.JPG");
// jLabel2.setIcon(b);
}
//***************************學(xué)生查詢(xún)成績(jī)***********************
public static void main(String[] args) {
chaxunchengji chaxunchengji = new chaxunchengji();
}
//Login l=new Login();
public void jButton1_actionPerformed(ActionEvent e) {
//System.out.println(username);
String Field1= jTextField1.getText().trim();
if(Field1.equals(""))
{
JOptionPane.showMessageDialog(null, "請(qǐng)輸入你的學(xué)號(hào)");
}//end if
else
{
try{
String sql = "select * from chengjibiao where id='" + Field1 + "'";
queryDataSet1.close();
//將SQL語(yǔ)句傳給queryDataSet1執(zhí)行。
queryDataSet1.setQuery(new QueryDescriptor(database1, sql, null, true,
Load.ALL));
queryDataSet1.open(); //將queryDataSet1打開(kāi)
queryDataSet1.refresh(); //刷新queryDataSet1
}//end try
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "Sorry!沒(méi)有你要的信息,請(qǐng)檢查你的學(xué)號(hào)錯(cuò)誤!");
}//end catch
}//end else
}
public int zengfeng;
public int SUM;
//***************************計(jì)算平均分*********************************
public void jButton2_actionPerformed(ActionEvent e) {
String Field1= jTextField1.getText().trim();
if(Field1.equals(""))
{
JOptionPane.showMessageDialog(null, "請(qǐng)輸入你的學(xué)號(hào)");
}//end if
else{
try{
Jdbcconn conn = new Jdbcconn();
//連接數(shù)據(jù)庫(kù)
conn.OpenConn("student", "sa", "zjxy2006");
String sql = "select sum(result) as zengfeng from chengjibiao where id='" + Field1 + "'";
try{
ResultSet rs = conn.getResults(sql);
rs.first();
SUM=rs.getInt(zengfeng);
JOptionPane.showMessageDialog(null,"統(tǒng)計(jì)總分:"+rs.getInt(zengfeng));
//jTextField2.setText(""+SUM);
}catch(Exception ex)
{
System.out.println(ex.getMessage());
}
/* queryDataSet1.close();
//將SQL語(yǔ)句傳給queryDataSet1執(zhí)行。
queryDataSet1.setQuery(new QueryDescriptor(database1, sql, null, true,
Load.ALL));
queryDataSet1.open(); //將queryDataSet1打開(kāi)
queryDataSet1.refresh(); //刷新queryDataSet1
jdbTable1.getColumn(4);
*/
}//end try
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "Sorry!沒(méi)有你要的信息,請(qǐng)檢查你的學(xué)號(hào)錯(cuò)誤!");
}//end catch
}//end else
}
}
class chaxunchengji_jButton2_actionAdapter
implements ActionListener {
private chaxunchengji adaptee;
chaxunchengji_jButton2_actionAdapter(chaxunchengji adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class chaxunchengji_jButton1_actionAdapter
implements ActionListener {
private chaxunchengji adaptee;
chaxunchengji_jButton1_actionAdapter(chaxunchengji adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -