大佬教程收集整理的这篇文章主要介绍了通过 Java 以编程方式自动将 Statement 更改为 Prepared Statement(在源代码中),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我被分配了一项任务,为了安全起见,将语句自动转换为准备好的语句。由于这是一项重复性任务,我想将其自动化。
例如
public @R_675_10495@ng getemployee(Connection connection,Long ID,Long groupID) {
@R_675_10495@ng result = "";
try {
Statement stmt = connection.createStatement();
@R_675_10495@ng query = "SELEct * from employee"
+ " where ID = " + ID ; // flaw 1
if(groupID != null) {
query += " and group_ID = " + groupID; // flaw 2
}
ResultSet rs = stmt.executequery(query);
}
我想用 :
消除缺陷public @R_675_10495@ng getemployee(Connection connection,Long groupID) {
@R_675_10495@ng result = "";
try {
@R_675_10495@ng query = "SELEct * from employee"
+ " where ID = ? ";
if(groupID != null) {
query += " and group_ID = ? ";
}
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setLong(parameterIndex++,ID);
stmt.setLong(parameterIndex++,groupID);
ResultSet rs = stmt.executequery();
}
我需要写一个java代码,可以用准备好的语句替换这些语句。
输入将是 java 文件。
我尝试了很多,但找不到解决此问题的可能方法。
如果可行的话,你能帮我指导一下吗。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的通过 Java 以编程方式自动将 Statement 更改为 Prepared Statement(在源代码中)全部内容,希望文章能够帮你解决通过 Java 以编程方式自动将 Statement 更改为 Prepared Statement(在源代码中)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。