jdbc操作mysql数据库(防止注入攻击版本)
来源:互联网 发布:小黑特价淘宝u站 编辑:程序博客网 时间:2024/05/26 02:52
package TestJDBC;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.Statement;public class SQLDemo { public static void main(String[] args) { SQLDemo demo = new SQLDemo(); //demo.login("a' or 'a'='a", "a' or 'a'='a"); demo.login("zs", "zs"); } public static Connection getConnection() throws Exception{ Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/web08"; return DriverManager.getConnection(url, "root", "root"); } public void login(String username,String password){ Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try{ conn = getConnection(); String sql = "select * from user where username=? and password=?"; ps = conn.prepareStatement(sql); ps.setString(1, username); ps.setString(2, password); rs = ps.executeQuery(); if(rs.next()){ System.out.println("欢迎:"+rs.getString("username")); }else { System.out.println("用户名或密码错误"); } }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(rs!=null) rs.close(); if(ps!=null) ps.close(); if(conn!=null) conn.close(); }catch(Exception e){ e.printStackTrace(); } } }}
0 0
- jdbc操作mysql数据库(防止注入攻击版本)
- 数据库注入攻击和防止注入攻击
- php 编程下有效防止MySQL数据库注入攻击
- PHP+MYSQL如何防止脚本注入攻击
- MySQL数据库防止SQL注入
- JDBC相关的知识点+大数据处理+防止sql注入攻击
- 防止注入式攻击
- SQL注入防止攻击
- 防止sql注入攻击
- 防止SQL注入攻击
- 防止SQL注入攻击
- 防止网站注入攻击
- 防止SQL注入攻击
- PHP防止注入攻击
- 防止sql注入攻击
- 防止SQL注入攻击
- 防止JavaScript注入攻击
- 防止SQL注入攻击
- Animation导致removeView无效(源码分析)
- android中使用SAX解析xml(封装)
- Makefile
- 每日刷题:移除数组中重复元素
- android图片处理方法(不断收集中)
- jdbc操作mysql数据库(防止注入攻击版本)
- java基础12:集合
- Android 中的 Animation 应用
- dwr 教程
- MIT Algorithms(算法导论一)
- 如何读取assets文件夹中的txt文件
- 在nginx和php-fpm下一访问nginx就瞬间502的问题 php-fpm signal 7 (SIGBUS)
- android获取手机电量
- Android事件传递机制(一)