* 模拟sql注入,使用preparedstatment防止sql注入
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* 模拟sql注入,使用preparedstatment防止sql注入
* @author 可敢离我近点
*
*/
public class SqlInjection {
public static void main(String[] args) {
/**
* 如果需要在finally块中手动关闭,就需要在try外声明
* 如果想要让其自动的关闭,则可以在try后面加一个括号初始化
* 先关闭statement,后关闭connection
* resultset结果集不需要手动关闭,他会在你关闭statement时自动的关闭
*/
Connection con=null;
PreparedStatement ps = null;
Statement st = null;
int i = 0;
//初始化驱动
try {
Class.forName("com.mysql.jdbc.Driver"