📄 sqlservermobiledao.java
字号:
package com.chinamobile.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import com.chinamobile.bean.MobileBean;
import com.chinamobile.bean.OperatorBean;
public class SQLServerMobileDAO implements MobileDAO {
private final String INSERT_AN_MOBILE = "insert into TMobile values(?,?,?,?)";
private final String GET_AN_MOBILE = "select * from TMobile where Mobile_Number=?";
public boolean createMobile(MobileBean mobile) {
Connection conn =null;
PreparedStatement pstmt=null;
boolean tmp=true;
try{
conn=SQLServerDAOFactory.getConnection();
pstmt=conn.prepareStatement(INSERT_AN_MOBILE);
pstmt.setString(1, mobile.getMobile_Number());
pstmt.setString(2, mobile.getMobile_Type());
pstmt.setString(3, mobile.getCard_Number());
pstmt.setString(4, mobile.getIs_Available());
int result=pstmt.executeUpdate();
if(result!=1)
tmp = false;
}catch(SQLException e){
tmp = false;
e.printStackTrace();
}finally{
SQLServerDAOFactory.closeStatement(pstmt);
SQLServerDAOFactory.closeConnection(conn);
}
return tmp;
}
public boolean isExists(MobileBean mobile) {
Connection conn =null;
PreparedStatement pstmt=null;
boolean tmp=true;
try{
conn=SQLServerDAOFactory.getConnection();
pstmt=conn.prepareStatement(GET_AN_MOBILE);
pstmt.setString(1, mobile.getMobile_Number());
ResultSet result=pstmt.executeQuery();
if(result.next()){
tmp = true;
}else{
tmp = false;
}
}catch(SQLException e){
e.printStackTrace();
}finally{
SQLServerDAOFactory.closeStatement(pstmt);
SQLServerDAOFactory.closeConnection(conn);
}
return tmp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -