jdbc防止sql注入-PreparedStatement

简介:

jdbc防止sql注入

jdbc防止sql注入-PreparedStatement 


public List getUserByName(String name,String password){
        ResultSet rs = null;
        PreparedStatement stat = null;
        Connection conn = null;
        List list = new ArrayList();
        try {
            conn = createConnection();
            
            String sql = "select name,password from manager where  name=? and password=? ";
            stat = conn.prepareStatement(sql);
            stat.setString(1, name);
            stat.setString(2, password);
            rs = stat.executeQuery();  
            while (rs.next()) {
                System.out.println(rs.getString(1));
                String []user = new String[2];
                user[0] = rs.getString(1);
                user[1] = rs.getString(2);
                list.add(user);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeAll(rs, stat, conn);
        }
        return list;
    }



      本文转自yjflinchong 51CTO博客,原文链接:http://blog.51cto.com/yjflinchong/1164974,如需转载请自行联系原作者


相关文章
|
1月前
|
SQL 监控 安全
SQL注入的实现原理以及防止
SQL注入的实现原理以及防止
|
1月前
|
SQL Java 应用服务中间件
Java项目防止SQL注入的四种方案
Java项目防止SQL注入的四种方案
37 0
|
1月前
|
SQL 安全 测试技术
如何在 Python 中进行 Web 应用程序的安全性管理,例如防止 SQL 注入?
如何在 Python 中进行 Web 应用程序的安全性管理,例如防止 SQL 注入?
15 0
|
1月前
|
SQL 安全 API
|
2月前
|
SQL JSON 数据库
常见的sql注入类型闭合及符号
常见的sql注入类型闭合及符号
31 0
|
8天前
|
SQL 人工智能 算法
【SQL server】玩转SQL server数据库:第二章 关系数据库
【SQL server】玩转SQL server数据库:第二章 关系数据库
51 10
|
1月前
|
SQL 数据库 数据安全/隐私保护
Sql Server数据库Sa密码如何修改
Sql Server数据库Sa密码如何修改
|
18天前
|
SQL
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
16 0
|
8天前
|
SQL 算法 数据库
【SQL server】玩转SQL server数据库:第三章 关系数据库标准语言SQL(二)数据查询
【SQL server】玩转SQL server数据库:第三章 关系数据库标准语言SQL(二)数据查询
66 6