银行管理系统_Note-01

  这周开始进入银行管理系统的开发,使用到的工具:

  集成环境:Eclipse  原型设计:Axure  数据库:MySQL  用例图:Visio

任务:DAO层的设计

  1.数据库的搭建

    1.1下载MySQL的驱动,并将驱动导入到工程BankSystem目录下

    1.2建立数据库的桥接,通过Class.formName(com.mysql.jdbc.Driver)将JDBC和ODBC桥接上

    1.3连接数据库,通过return 一个DriverManager.getConnection(url,userName,pwd)方法得到的链接,在后续对数据库的操作时得到该连接,当                          然,这些步骤会抛出异常(本来中间还应该有一步:查找ODBC数据源,但是微软一般都默认给我们配好了,所以省去了那一步)

public class JdbcUtils {

    static {
        //建立数据库桥接
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    //连接数据库
    public static Connection getConn(){
        try {
            return DriverManager.getConnection("jdbc:mysql://localhost:3306/BankSystem", "root", "root");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
    
}

 

  2.对数据库进行操作

    2.1先在dao层声明一个操作数据库的接口,以用户(实体)为例:UserDAO,该接口中包含增删改查这些对数据库中数据的操作

    2.2在dao目录的下层dao.implement下创建实现对用户数据操作的类ImplementUserDAO,该类来实现上面的接口

public class ImplementUserDAO implements UserDAO {

    //1.增加
    public void add(User u, Connection con) {

        String sql = "insert into t_user(userId,personId,userName,userPwd,oldPwd,telphone,address,userType)"
                +"values(?,?,?,?,?,?,?,?)";
        try {
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, u.getUserId());
            ps.setString(2, u.getPersonId());
            ps.setString(3, u.getUserName());
            ps.setString(4, u.getUserPwd());
            ps.setString(5, u.getOldPwd());
            ps.setString(6, u.getTelphone());
            ps.setString(7, u.getAddress());
            ps.setInt(8, u.getUserType());
            
            ps.executeUpdate();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

 

转载于:https://www.cnblogs.com/Jerry-java/p/5407734.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <stdio.h>#include <string.h>#include <stdlib.h>#define MAX_SMS_LENGTH 200#define MAX_NAME_LENGTH 8#define MAX_PHONE_LENGTH 11typedef struct { char word[MAX_SMS_LENGTH]; /*短信内容*/ int length; /*短信长度*/} Message;typedef struct { char name[MAX_NAME_LENGTH]; /*姓名*/ char phone[MAX_PHONE_LENGTH]; /*电话号码或手机号码*/} Note;void extract_phone_number(Message* message, Note* note) { int start = 0; int phone_start = -1; int phone_end = -1; while (start < message->length) { if (message->word[start] >= '0' && message->word[start] <= '9') { phone_start = start; phone_end = start; start++; while (start < message->length && message->word[start] >= '0' && message->word[start] <= '9') { phone_end = start; start++; } if (phone_end - phone_start == 6 || phone_end - phone_start == 7) { strncpy(note->phone, message->word + phone_start, phone_end - phone_start + 1); note->phone[phone_end - phone_start + 1] = '\0'; } else if (phone_end - phone_start == 10 || phone_end - phone_start == 11) { strncpy(note->phone, message->word + phone_start, phone_end - phone_start + 1); note->phone[phone_end - phone_start + 1] = '\0'; } if (strlen(note->phone) > 0) { break; } } else { start++; } }}void save_to_contact(Note* note) { // 将 note 存储到通讯录中}int main() { Message message; Note note; // 读取短信 fgets(message.word, MAX_SMS_LENGTH, stdin); message.length = strlen(message.word) - 1; message.word[message.length] = '\0'; memset(note.name, 0, MAX_NAME_LENGTH); memset(note.phone, 0, MAX_PHONE_LENGTH); extract_phone_number(&message, &note); save_to_contact(&note); return 0;}
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值