public static void main(String args[]) { new MainWindow(); } }
(2)连接数据库代码:
package Stu;
import java.sql.*;
import javax.swing.*;
//有关球队信息数据库操作的类 public class TeamBean { String sql;
ResultSet rs = null; String sNum; String sName; String sScore; //添加球队信息
public void stuAdd(String num, String name) {
Database DB = new Database(); this.sNum = num; this.sName = name;
if(sNum == null||sNum.equals(\)){
JOptionPane.showMessageDialog(null, \请输入球队号!\, \错误\, JOptionPane.ERROR_MESSAGE); return; }
else if(sName == null||sName.equals(\)){
JOptionPane.showMessageDialog(null, \请输入球队名!\, \错误\, JOptionPane.ERROR_MESSAGE); return; }
else{
sql = \
('\+sNum+\+sName+\;//,'\;
try{
DB.OpenConn();
DB.executeUpdate(sql);
10
JOptionPane.showMessageDialog(null,\成功添加一条新的纪录!\); }
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null, \保存失败\, \错误\, JOptionPane.ERROR_MESSAGE); }
finally {
DB.closeStmt(); DB.closeConn(); } } }
// 修改球队信息
public void stuModify(String num, String name){
Database DB = new Database(); this.sNum = num; this.sName = name;
sql = \+sNum+\+sName+\\+Integer.parseInt(sNum)+\; try{
DB.OpenConn();
DB.executeUpdate(sql);
JOptionPane.showMessageDialog(null,\成功修改一条新的纪录!\); }
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null, \更新失败\, \错误\, JOptionPane.ERROR_MESSAGE); }
finally {
DB.closeStmt(); DB.closeConn(); } }
//删除球队信息
public void stuDel(String num){
Database DB = new Database();
11
this.sNum = num;
sql = \+Integer.parseInt(sNum)+\; try{
DB.OpenConn();
DB.executeUpdate(sql);
JOptionPane.showMessageDialog(null,\成功删除一纪录!\); }
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null, \删除失败\, \错误\, JOptionPane.ERROR_MESSAGE); }
finally {
DB.closeStmt(); DB.closeConn(); } }
// 根据球队号查询球队信息
public String[] stuSearch(String num){
Database DB = new Database(); this.sNum = num;
String[] s = new String[5];
if(sNum == null||sNum.equals(\)){
JOptionPane.showMessageDialog(null, \请输入球队号!\, \错误\, JOptionPane.ERROR_MESSAGE); }
sql = \+Integer.parseInt(sNum)+\; try{
DB.OpenConn();
rs = DB.executeQuery(sql); if(rs.next()){
s[0] = rs.getString(\); }
else{
s = null; } }
catch(Exception e){} finally {
DB.closeStmt();
12
DB.closeConn(); }
return s; }
// 修改球队积分信息
public void stuModify1(String num, String score){
Database DB = new Database(); this.sNum = num; this.sScore = score;
sql = \+sNum+\+sScore+\\+Integer.parseInt(sNum)+\; try{
DB.OpenConn();
DB.executeUpdate(sql);
JOptionPane.showMessageDialog(null,\成功修改一条新的纪录!\); }
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null, \更新失败\, \错误\, JOptionPane.ERROR_MESSAGE); }
finally {
DB.closeStmt(); DB.closeConn(); } }
//根据球队号查询球队积分信息
public String[] stuSearch1(String num){
Database DB = new Database(); this.sNum = num;
String[] s = new String[5];
if(sNum == null||sNum.equals(\)){
JOptionPane.showMessageDialog(null, \请输入球队号!\, \错误\, JOptionPane.ERROR_MESSAGE); }
sql = \+Integer.parseInt(sNum)+\; try{
DB.OpenConn();
13
rs = DB.executeQuery(sql); if(rs.next()){
s[0] = rs.getString(\); } else{
s = null; } }
catch(Exception e){} finally {
DB.closeStmt(); DB.closeConn(); }
return s; }
//删除积分信息
public void stuDel1(String num){
Database DB = new Database(); this.sNum = num;
sql = \+Integer.parseInt(sNum)+\; try{
DB.OpenConn();
DB.executeUpdate(sql);
JOptionPane.showMessageDialog(null,\成功删除一纪录!\); }
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null, \删除失败\, \错误\, JOptionPane.ERROR_MESSAGE); }
finally {
DB.closeStmt(); DB.closeConn(); } }
//添加球队积分信息
public void stuAdd1(String num, String score) {
14