在JDBC查询中使用表名作为参数的安全方法

编程入门 行业动态 更新时间:2024-10-26 10:29:53
本文介绍了在JDBC查询中使用表名作为参数的安全方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

将表名作为参数放在SQL查询中的安全方法是什么?您不能使用 PreparedStatement 将表格名称作为参数。连接字符串以使用动态表名使用 Statement 是可能的,但是不推荐使用SQL注入的风险。这样做最好的方法是什么?

What is the safe way how to put table name as parameter into SQL query? You cannot put table name as parameter using PreparedStatement. Concatenating string to execute query with dynamic table name using Statement is possible, however it is not recommended because of risk of SQL injection. What is the best approach to do this?

推荐答案

我会尝试解决设计问题,所以你不必动态设置表名。如果这是不可能的,我会去一个设计,在那里您管理一个可用的表和用户列表,用户从其中选择一个BY ID,以便您可以从所选的ID中检索真实的表名,并将其替换为表名占位符,避免在表名中替换sql注入的任何机会。

I would try to solve the design problem, so you don't have to set the table name dynamically. If this is not possible, I would go for a design where you manage a list of available tables and users pick one from there, BY ID, so you can retrieve the real table name from the chosen id and replace the table name placeholder with it, avoiding any chance of sql injection in the table name replacement.

更多推荐

在JDBC查询中使用表名作为参数的安全方法

本文发布于:2023-10-23 01:45:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519375.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   方法   JDBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!