首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

至于prepareStatement.setInt的使用

2011-11-08 
关于prepareStatement.setInt的使用private boolean isFirstAnsw(int userphone){int current db new DB

关于prepareStatement.setInt的使用
private boolean isFirstAnsw(int userphone){

int current;
db= new DBConn();
conn = db.getConnection();
try {
String sql = "select * from useransw where userphonenum = ?";
ps = conn.prepareStatement(sql);
//String sql = "select * from useransw where userphonenum = "+userphone;
ps.setInt(1, userphone);
rs = ps.executeQuery(sql);
if(rs.next()){
current = rs.getInt("CURRENT");
if(current!=0){
return false;
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
db.close(conn, stmt, rs);
}
return true;

}

这是判断一个用户是否是第一次登入的代码,我不明白中间为什么要使用ps.setInt(1, userphone); 是什么作用。

[解决办法]
简单点说

String sql = "select * from useransw where userphonenum = ?"; 
这句话里不是有个问号么 
ps.setInt(1, userphone); 这句话的意思就是把第一个问题所在的地方换成userphone

[解决办法]
String sql = "select * from useransw where userphonenum = ?";
ps.setInt(1, userphone)的意思是设置sql的第一个参数也就是第一个问号值为userphone

热点排行