1、指导教师 x x二一六 年 六 月十三日附录1存储过程定义1) 查看所有会员表中的数据2) 查看所有会员资料表中的数据:3) 查看某张卡数据:4) 修改会员卡状态数据(挂失、冻结、回复)5) 查看某个会员资料的数据:6) 给会员卡充值:7) 7)给会员卡消费:附录2 数据查看和存储过程功能的验证1. 基本表的数据录入:1) 会员基本信息表中的数据附录3 源代码package com.connection;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;impor
2、t java.sql.ResultSet;import java.sql.SQLException;public class GetConnection private String classname =com.microsoft.sqlserver.jdbc.SQLServerDriver;private String url =jdbc:sqlserver:/localhost:1433;DatabaseName=yygglprivate String userName=saprivate String pswd = 111111public Connection getConnecti
3、on()Connection conn ;try Class.forName(classname);conn = DriverManager.getConnection(url, userName, pswd); catch (Exception e) / TODO: handle exceptionSystem.out.println(连接失败.);conn=null;e.printStackTrace();return conn;public void closed(ResultSet rs,PreparedStatement pstm,Connection conn)if(pstm!=n
4、ull)pstm.close(); catch (SQLException e) / TODO Auto-generated catch block关闭pstm对象失败!if(conn!关闭conn对象失败!package com.dao;import com.Model.AdminModel;import com.Model.CardModel;import com.connection.GetConnection;public class AdminDao private Connection conn=null;private ResultSet rs=null;private Prep
5、aredStatement pstm=null;private GetConnection connection = new GetConnection();int key=1;public int updateAdmin(String kh,String kzt)/ 根据卡号修改 卡状态int n=0;conn=connection.getConnection();String sql=update Admin set 账号=? , 密码=? where id=?pstm=conn.prepareStatement(sql);pstm.setString(1, kzt);pstm.setSt
6、ring(2, kh);pstm.setInt(3, key);n=pstm.executeUpdate(); finallyconnection.closed(rs, pstm, conn);return n;public AdminModel selectAdmin() /按卡号查询+AdminModel Card=new AdminModel();tryselect * from Admin where id=? pstm.setInt(1, key);rs=pstm.executeQuery();while(rs.next()/ String kh=rs.getString(卡号Str
7、ing xm=rs.getString(账号String zk=rs.getString(密码 System.out.println(kzt);Card=new AdminModel(xm,zk);catch(SQLException e)finallyreturn Card;import java.util.ArrayList;import java.util.List;import javax.swing.JOptionPane;import com.Model.*;public class CardDao public ListselectCardAll() / 查询所有卡Listlis
8、t=new ArrayList();select * from Cardpstm = conn.prepareStatement(sql);rs = pstm.executeQuery();String kh=rs.getString(姓名int je=rs.getInt(结余金额折扣String kzt=rs.getString(卡状态CardModel Card=new CardModel(kh,xm,je,zk,kzt);list.add(Card);/ TODO 自动生成的 catch 块return list;public boolean checkCard(String kh) 根
9、据卡号检查卡是否存在boolean exists=false;String sql = Select 卡号From Card where 卡号=?pstm.setString(1, kh);if (rs.next()exists = true;return exists;public int insertCard(String kh,String xm,int a,String zk,String kzt) /添加新卡if(checkCard(kh)JOptionPane.showMessageDialog(null,该卡已存在,不能添加!,错误,JOptionPane.ERROR_MESSAGE);return -1;insert into Card(卡号,姓名,结余金额,折扣,卡状态) values(?,?) pstm.setString(2, xm);pstm.setInt(3, a);pstm.setString(4,zk);pstm.setString(5, kzt); catch
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1