验证用户输入JDBC的最佳方法? [英] Best way to validate user input JDBC?

查看:103
本文介绍了验证用户输入JDBC的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在使用JDBC在Java中转义用户输入的内置方法?类似于php版本mysql_real_escape()函数.验证输入的最佳方法是什么?

Is there a built-in way to escape user input in java using the JDBC? Something similar to the php version mysql_real_escape() function. What's the best way to validate input?

推荐答案

如果您的意思是如何确保用户输入不能在SQL注入攻击中使用,那么执行此操作的方法(以及应使用的所有SQL方法)用JDBC编写)正在使用预准备语句. JDBC将自动处理任何必要的转义.

If you mean how do you make sure user input can't be used in SQL injection attacks, the way to do this (and the way all SQL should be written in JDBC) is using Prepared Statements. JDBC will automatically handle any necessary escaping.

http://java.sun.com/docs /books/tutorial/jdbc/basics/prepared.html

这篇关于验证用户输入JDBC的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆