Win.javaimport java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;public class Win extends JFrame implements ActionListener { JTextField text[]=new JTextField[6];JTextArea show=new JTextArea(9,30);JTable table;//标签JButton insert,update,select,delete,C,Q;Win() {setLayout(new FlowLayout());for(int i=0;i<5;i++) {text[i]=new JTextField(10);}add(new JLabel("卡号:"));add(text[0]);add(new JLabel("姓名:"));add(text[1]);add(new JLabel("密码:"));add(text[2]);add(new JLabel("余额:"));add(text[3]);add(new JLabel("序号:"));add(text[4]);C=new JButton("存款");C.addActionListener(this);add(C);Q=new JButton("取款");Q.addActionListener(this);add(Q);update=new JButton("修改密码");update.addActionListener(this);add(update);insert=new JButton("添加新用户");insert.addActionListener(this);add(insert);select=new JButton("查询用户信息");select.addActionListener(this);add(select);delete=new JButton("删除用户信息");delete.addActionListener(this);add(delete);add(new JScrollPane(show));add(new JLabel("提示:1.每次取款金额为100的倍数,总额不能超过5000元,支取金额不允许透支"));add(new JLabel("2.存款金额不能为负存款"));add(new JLabel("3.新密码长度不小于6位,不允许出现6位完全相同的情况"));setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e) {Operation modify=new Operation();modify.setDatasourceName("XX");if(e.getSource()==insert){modify.setSQL("INSERT INTO XX VALUES('"+text[4].getText()+"','"+text[0].getText()+"','"+text[1].getText()+"','"+tex t[2].getText()+"','"+text[3].getText()+"')");String backMess=modify.modifyRecord();show.append("添加新用户"+backMess);}else if(e.getSource()==C){Connection con=null;Statement sql;ResultSet rs = null;try{double n=2000;con=DriverManager.getConnection("jdbc:odbc:XX","","");con.setAutoCommit(false);sql=con.createStatement();rs=sql.executeQuery("SELECT * FROM XX WHERE 卡号='123456'");//查询rs.next();double money=rs.getDouble(5);System.out.println("操作前用户的余额:"+money);double money1=money+n; //存款sql.executeUpdate("UPDATE XX SET 余额=+'"+money1+"' WHERE 卡号='123456'"); //存款后更新余额mit();con.setAutoCommit(true); //提交事务结果到数据库sql=con.createStatement(); //创建数据库操作对象}catch(SQLException e1){ try{ con.rollback(); } //如果操作失败则结束事务catch(SQLException exp){}System.out.println(""+e);}}else if(e.getSource()==Q){ Connection con=null;Statement sql;ResultSet rs = null;try{double n=5000;con=DriverManager.getConnection("jdbc:odbc:XX","","");con.setAutoCommit(false);sql=con.createStatement();rs=sql.executeQuery("SELECT * FROM XX WHERE 卡号='123456'");rs.next();double money=rs.getDouble(5);System.out.println("操作前用户的余额:"+money);double money2=money-n; //取款sql.executeUpdate("UPDATE XX SET 余额=+'"+money2+"' WHERE 卡号='123456'"); //取款后更新余额mit();con.setAutoCommit(true);sql=con.createStatement();}catch(SQLException e1){ try{ con.rollback(); }catch(SQLException exp){}System.out.println(""+e);}}else if(e.getSource()==update){modify.setSQL("UPDATE XX SET XX.密码 =+'"+text[2].getText()+"' WHERE (((XX.卡号)=+'"+text[0].getText()+"'));");String backMess=modify.modifyRecord();show.append("修改密码"+backMess);}else if(e.getSource()==delete){modify.setSQL("DELETE * FROM XX WHERE (((XX.卡号)=+'"+text[0].getText()+"'));");String backMess=modify.modifyRecord();show.append("删除用户信息"+backMess);}else if(e.getSource()==select){Query query =new Query();query.setDatasoureName("XX");query.setTableName("XX");Object a[][]=query.getRecord();String b[]={"序号","卡号","姓名","密码","余额"};table=new JTable(a,b);JFrame frame=new JFrame();frame.add(new JScrollPane(table));frame.setVisible(true);frame.setBounds(400,400,600,200);}}public void setBounds(int i, int j, int k, int l) {}}Operation.javaimport java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Statement;public class Operation{String datasourceName=""; //数据源名称String SQL,message=""; //表名public Operation() //增删改的主代码{try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } //操作数据源catch(Exception e){}}public void setSQL(String SQL) //建立一个新的数据源{ this.SQL=SQL; }public void setDatasourceName(String s){ datasourceName=s.trim(); }public String modifyRecord(){Connection con=null;Statement sql=null;try{ String uri="jdbc:odbc:"+datasourceName;String id="";String password="";con=DriverManager.getConnection(uri,id,password);sql=con.createStatement();sql.execute(SQL);message="操作成功";con.close();}catch(SQLException e){ message=e.toString(); }return message;} /*数据源读取初始化*/public void setTableName(String string) {} //表名public Object[][] getRecord() //存放操作结果数组{ return null; }}Query.javaimport java.sql.*;import .httpserver.Authenticator.Result;public class Query{ String datasourceName=""; //数据源名String tableName=""; //表名Object a[][];public Query(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");} //桥接器 catch(ClassNotFoundException e){System.out.print(e);}}public void setDatasoureName(String s){ datasourceName=s.trim(); }public void setTableName(String s){ tableName=s.trim(); }public Object[][] getRecord() //获取表中记录{Connection con;PreparedStatement sql; //预处理命令ResultSet rs; //结果集try{String uri="jdbc:odbc:"+datasourceName;String number="";String password="";con=DriverManager.getConnection(uri,number,password); //初始化连接DatabaseMetaData metadata=con.getMetaData();//连接对象调用getMetaData()方法返回一个DatabaseMetaData对象ResultSet rs1=metadata.getColumns(null,null,tableName,null);//将表中的字段信息以行列的形式存储在Result中int 字段个数=0;while(rs1.next()){ 字段个数++;}int n=getAmount();a=new Object[n][字段个数];sql=con.prepareStatement("SELECT * FROM "+tableName); //查询表名rs=sql.executeQuery();int m=0;while(rs.next()) //输出结果集中的数据{ for(int k=1;k<=字段个数;k++){ a[m][k-1]=rs.getString(k); }m++;}con.close();}catch(SQLException e){ System.out.println("请输入正确的表名"+e); }return a;}public int getAmount(){Connection con;Statement sql;ResultSet rs;try{String uri="jdbc:odbc:"+datasourceName;String id="";String password="";con=DriverManager.getConnection(uri,id,password);sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_RE AD_ONLY); //以只读方式滚动查询rs=sql.executeQuery("SELECT * FROM "+tableName); //获取所在行st();int rows=rs.getRow(); //当前游标所指行号return rows;}catch(SQLException exp){System.out.println(""+exp);return 0;}}public void inputQueryResult() {}}ATM.javapublic class ATM {public static void main(String args[]){ Win win=new Win();win.setBounds(400,300,400,300); //设置组件在容器中的位置和本身的大小win.setTitle("ATM自动柜员机");}}。