4、DAO接口实现类:
package com.song.Impl; import java.sql.*; import com.song.DAO.RegisterDAO; import com.song.VO.RegisterBean; import com.song.DB.*; public class RegisterImpl implements RegisterDAO{ public void insert(RegisterBean registerBean)throws Exception{ String sql = "insert into register(username,password,email) values (?,?,?)"; PreparedStatement pstmt = null; Connection conn = null; DataBaseConnection dbconn = null; try{ dbconn = new DataBaseConnection(); conn = dbconn.getConn(); pstmt = conn.prepareStatement(sql); pstmt.setString(1,registerBean.getUsername()); pstmt.setString(2,registerBean.getPassword()); pstmt.setString(3,registerBean.getEmail()); pstmt.executeUpdate(); pstmt.close(); conn.close(); }catch(Exception e){ System.out.println("数据插入失败!"); e.printStackTrace(); }finally{ dbconn.close(); } } }
时间: 2024-09-17 14:01:43