?? 修改成績.java
字號:
/*
* 修改成績.java
*
* Created on 2008年10月10日, 上午10:14
*/
package javaapplication1;
import java.sql.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
/**
*
* @author mis06
*/
public class 修改成績 extends javax.swing.JPanel {
/** Creates new form 修改成績 */
public 修改成績() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel1.setText("\u5b66\u53f7");
jLabel2.setText("\u8bfe\u7a0b\u53f7");
jLabel3.setText("\u6210\u7ee9");
jButton1.setText("\u4fee\u6539");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton3.setText("\u67e5\u770b\u6210\u7ee9");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(19, 19, 19)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jButton3)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(jLabel2)
.add(jLabel3))
.add(9, 9, 9)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jTextField3)
.add(jTextField2)
.add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
.add(43, 43, 43)
.add(jButton1)))
.addContainerGap(149, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(27, 27, 27)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(31, 31, 31)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(layout.createSequentialGroup()
.add(54, 54, 54)
.add(jButton3)))
.add(37, 37, 37)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel3)
.add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1))
.addContainerGap(142, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
Statement statement;
try{
Connect con = new Connect();
statement= con.con.createStatement();
String studentNumber=jTextField1.getText();
String courseNumber=jTextField2.getText();
String score0 =null;
String sql1="select 成績 from 成績 where 學(xué)號='"+studentNumber+"' AND 課程號='"+courseNumber+"'";
ResultSet resultSet=statement.executeQuery(sql1);
ResultSetMetaData metaData=resultSet.getMetaData();
int numberOfColumns=metaData.getColumnCount();
while(resultSet.next())
{
for(int i=1;i<=numberOfColumns;i++)
score0=resultSet.getObject(i).toString();
}
jTextField3.setText(score0);
}
catch(SQLException sqlException){
JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
System.exit(1);}
catch(ClassNotFoundException classNotFound){
JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
System.exit(1); }// TODO add your handling code here:
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
Statement statement;
try{
Connect con = new Connect();
statement= con.con.createStatement();
String studentNumber=jTextField1.getText();
String courseNumber=jTextField2.getText();
String score0 =jTextField3.getText();
String sql2="update 成績 set 成績="+score0+" where 學(xué)號='"+studentNumber+"' AND 課程號='"+courseNumber+"'";
int reg= statement.executeUpdate(sql2);
if(reg==1)
JOptionPane.showMessageDialog(null,"成功修改成績");
else
JOptionPane.showMessageDialog(null,"不存在該學(xué)生或課程!");
}
catch(SQLException sqlException){
JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
System.exit(1);}
catch(ClassNotFoundException classNotFound){
JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
System.exit(1); }// TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration//GEN-END:variables
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -