24,923
社区成员
发帖
与我相关
我的任务
分享
String SQL="INSERT INTO king_channel(uid,url,channelname,encode,status,lastbuildate,path)VALUES(?,?,?,?,?,?,?)";
int rid=0;
Connection conn=null;
PreparedStatement ps=null;
try {
conn=JdbcUtil.getInstance();
ps=conn.prepareStatement(SQL,new String[]{"rid"});
ps.setInt(1,userId);
ps.setString(2, rssUrl);
ps.setString(3, channelName);
ps.setString(4, encode);
ps.setString(5, status);
ps.setLong(6, UtilCollection.converJavaTimeStampToPhp(lastbuildate.getTime()));
ps.setString(7, visPath);
ps.executeUpdate();
ResultSet rs=ps.getGeneratedKeys();
if(rs!=null && rs.next()){
rid=rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
return 0;
}finally{
JdbcUtil.release(ps);JdbcUtil.release(conn);
}
return rid;
public int associateSpecialChannel(int userId, int channelID) {
// TODO Auto-generated method stub
//ChannelSQL.ASSOCIATE
String SQL="INSERT INTO king_user_channel(uid,rid)VALUES(?,?)";
int record=0;
Connection conn=null;
PreparedStatement ps=null;
try {
conn=JdbcUtil.getInstance();
ps=conn.prepareStatement(SQL,new String[]{"ucid"});
ps.setInt(1, userId);
ps.setInt(2, channelID);
record=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
return 0;
}finally{
JdbcUtil.release(ps);JdbcUtil.release(conn);
}
return record;
}
3.这样做的会不会导致,当两个用户AB同时访问这个servlet的时候,A用户读取到B用户的id啊
不会,可以放心使用,如果是特殊的实体:像订单号或会员ID最好是事先根据属性生成,不要用自增ID
订单号:可以根据地区+日成交量+商品类型+时间点
会员ID:可以根据:身份证或邮箱或手机号定一个算法生成一个uid
数据库表的主键最好要有意义,