在调试时如何打印出一个完整的SQL语句?
1.问题1
我在写sql语句时,用?代替一系列变量,然后用PreparedStatement 中的方法
分别给?对应的变量赋值,我想知道在System.out.println(strSql)时
如何打印出来一个给?赋值后的完整的SQL语句?
2.问题2
用PreparedStatement 和用Statement 有何区别?
实例如下:
PreparedStatement ps=null;
String strSql="";
strSql="insert into jia_purch(hp_bianh,hp_mingc,hp_guig,hp_gouhjg,hp_gouhsl) "
+" values(?,?,?,?,?)";
ps=con.prepareStatement(strSql);
ps.setString(1,purchDO.getHPbianh()) ; //货品编号
ps.setString(2,purchDO.getHPmingc()) ; //货品名称
ps.setString(3,purchDO.getHPguig()) ; //货品规格
ps.setDouble(8,purchDO.getHPgouhjg()); //购货价格
ps.setInt(9,purchDO.getHPgouhsl()); //购货数量
ps.executeUpdate();
在执行上面的语句时,出错了,我想将给变量?赋值后的SQL语句打印出来,
应该如何处理呀?