代码大概如下
String sql_1 = "select * from or_detail where orderId=? and productCode=?"
String str_1 = request.getParameter("orderId");
String str_2 = request.getParameter("productCode");
ResultSet rs_1 = (new JDBCutil()).execute(sql_1,str_1,str_2);
if(rs_1.next()){
double price = rs_1.getDouble("price");
double qty = rs_1.getDouble("qty");
}
//JDBCutil 的execute方法如下
public ResultSet execute(String sql ,String str_1,String st_2){
session = this.getSession();
ResuleSet rs = null;
try{
conn = session.connection();
pstat = conn.prepareStatement(sql);
pstat.setString(1,str_1);
pstat.setString(2,str_2);
rs_1 = pstat.executeQuery();
}catch(Exception e){
e.printStackTrace();
}
return rs_1;
}
我接收的结果 就是无法进入 if循环
就是 我的rs_1.next() 为 false
------解决方案--------------------
先确定是否连接成功,之后查看一下你的str_1和str_2是否不为null。
之后你查看一下你的条件是否有对应的结果。
over
------解决方案--------------------
方法里的定义了rs, 但没用,而是给rs_1赋值,并返回rs_1,这个rs_1是否应是rs?
------解决方案--------------------
+1 楼主debug看一下吧 可能是造型的问题
------解决方案--------------------
str1的类型改为int,
String str_1 = request.getParameter("orderId");改为
int str_1=Integer.parseInt(request.getParameter("orderId"));