자바 SQL 주입 사례 튜 토리 얼 및 html 기초 입문
C1,수요
C1,jdbc 를 이용 하여 user 의 정 보 를 조회 하고 정보 가 정확 하면 로그 인 합 니 다.그렇지 않 으 면 오 류 를 알려 줍 니 다.
C1,user 표를 만 들 고 필드 id name password 를 지정 하 며 데 이 터 를 추가 합 니 다.
C2,jdbc 를 통 해 user 표 의 데 이 터 를 조회 하고 사용자 이름과 비밀번호 에 따라 찾 습 니 다.
C2,테스트
package cn.tedu.test;
import java.sql.*;
import java.util.Scanner;
//
/*
create table user(
id int primary key auto_increment,
name varchar(20),
password varchar(20)
)
insert into user values(null,'jack','123');
insert into user values(null,'rose','123');
*/
public class Test3 {
public static void main(String[] args) throws Exception {
// method(); //
// method2(); //
method3(); // SQL
}
private static void method3() throws Exception {
//1,
Class.forName("com.mysql.jdbc.Driver");
//2,
String url ="jdbc:mysql:///cgb2105?characterEncoding=utf8" ;//
Connection conn = DriverManager.getConnection(url, "root", "root");
//3,
// Statement st = conn.createStatement();
// String sql = "select * from user where name='"+a+"' and password='"+b+"'";
String a = new Scanner(System.in).nextLine();//
String b = new Scanner(System.in).nextLine();//
//SQL ,?
String sql = "select * from user where name=? and password=?";
//PreparedStatement SQL
// SQL :jack'# #
PreparedStatement ps = conn.prepareStatement(sql);
// SQL --
ps.setString(1,a);
ps.setString(2,b);
//4, SQL,
ResultSet rs = ps.executeQuery();
//5,
if( rs.next() ){ // next() true,
System.out.println(" ~~");
}else{
System.out.println(" !");
}
//6,
rs.close();//
ps.close();//
conn.close();//
}
private static void method2() throws Exception {
//1,
Class.forName("com.mysql.jdbc.Driver");
//2,
String url ="jdbc:mysql:///cgb2105?characterEncoding=utf8" ;//
Connection conn = DriverManager.getConnection(url, "root", "root");
//3,
Statement st = conn.createStatement();
//4, SQL,
String a = new Scanner(System.in).nextLine();//
String b = new Scanner(System.in).nextLine();//
//SQl /SQL : SQL 。jack'#
String sql = "select * from user where name='"+a+"' and password='"+b+"'";
ResultSet rs = st.executeQuery(sql);
//5,
if( rs.next() ){ // next() true,
System.out.println(" ~~");
}else{
System.out.println(" !");
}
//6,
rs.close();//
st.close();//
conn.close();//
}
// : user
private static void method() throws Exception {
//1,
Class.forName("com.mysql.jdbc.Driver");
//2,
//String url ="jdbc:mysql://localhost:3306/cgb2105?characterEncoding=utf8" ;
String url ="jdbc:mysql:///cgb2105?characterEncoding=utf8" ;//
Connection conn = DriverManager.getConnection(url, "root", "root");
//3,
Statement st = conn.createStatement();
//4, SQL,
String sql = "select * from user where name='jack' and password='123'";
ResultSet rs = st.executeQuery(sql);
//5,
if( rs.next() ){ // next() true,
System.out.println(" ~~");
}else{
System.out.println(" !");
}
//6,
rs.close();//
st.close();//
conn.close();//
}
}
C3,총괄SQL 공격 이 발생 하 는 현상 은 사용자 가 SQL 의 특수 문 자 를 입력 했 습 니 다.\#주석 을 표시 합 니 다.
Statement 도구:SQL 주입 문 제 를 피 할 수 없 으 며 SQL 이 복잡 할 때 스스로 매개 변 수 를 연결 해 야 합 니 다.비효 율 적 입 니 다.
Prepared Statement 도구:SQL 공격 문 제 를 피 할 수 있 고 SQL 이 간단 하고 효율 적 입 니 다.
CSQL 은 간단 합 니 다.먼저 SQL 골격 을 데이터베이스 에 보 낸 다음 에 매개 변 수 를 데이터베이스 에 보 냅 니 다.쓰다매개 변수 대신 위 치 를 차지 문자 라 고 합 니 다.
2.연습 Prepared Statement
C1,수요
id=1 사용자 정보 삭제
C2,테스트
package cn.tedu.test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Test4 {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement ps= null;
try{
// ,,,
conn = JDBCUtils.getConnection();
//3, , SQL
// SQL
String sql = "delete from user where id=?";
ps = conn.prepareStatement(sql);
// , 1
ps.setInt(1,1);
//4, SQL
int rows = ps.executeUpdate();
System.out.println(" ");
}catch (Exception e){
System.out.println(" ...");
}finally{ //
//5,
JDBCUtils.close(null,ps,conn);
}
}
}
C3,제작 도구 류
package cn.tedu.test;
import java.sql.*;
// jdbc ,
public class JDBCUtils {
/**
*
* @param rs
* @param ps
* @param conn
*/
final static public void close(ResultSet rs, PreparedStatement ps, Connection conn){
if(rs != null){//
try {
rs.close();
} catch (SQLException throwables) {
System.out.println(" ...");//
//throwables.printStackTrace();//
}
}
if(ps != null){//
try {
ps.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if(conn != null) {//
try {
conn.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
/**
*
* */
static public Connection getConnection() throws Exception {
//1,
Class.forName("com.mysql.jdbc.Driver");
//2,
String url="jdbc:mysql:///cgb2105?characterEncoding=utf8";
Connection conn = DriverManager.getConnection(url,"root","root");
return conn;
}
}
HTMLC1,개술
하이퍼텍스트 표기 언어 로 웹 페이지 에 텍스트 보다 풍부 한 내용 을 추가 할 수 있다 는 뜻 이다.태그 가 많 습 니 다.시작 표시 와 결과 표 시 를 써 야 합 니 다.
C2,입문 사례
html>
<head>
<title>hello html~</title>
</head>
<body>
test......
</body>
</html>
C3,도구 사용
<!DOCTYPE html> <!-- HTML -->
<html> <!-- HTML -->
<head> <!-- , , 。。。-->
<meta charset="utf-8"> <!-- -->
<title> html </title> <!-- -->
</head>
<body> <!-- , -->
<!-- HTML ,Hbuilder ctrl c/ctrl v , ctrl x, ctrl ↑↓ -->
html~
html~ <br/> <!-- br -->
html~ <!-- -->
html~
html~
html~
</body>
</html>
C4,테스트4.테스트 상용 태그
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> </title>
</head>
<body>
<!-- 1. h1 h2 h3...h6 -->
<h1> 1 </h1>
<h2> 2 </h2>
<h3> 3 </h3>
<h4> 4 </h4>
<h5> 5 </h5>
<h6> 6 </h6>
<!-- 2. , ul+li ol+li -->
<ol>
<li> 13 </li>
<li> </li>
<li> 05 </li>
<li> 757 8 </li>
</ol>
<!-- 3. ,
src
width , px
height , px
-->
<img src="a/2.jpg" width="200px" height="500px"/>
<img src="2.jpg" width="200px" height="500px"/>
<img src="2.jpg" width="200px" height="500px"/>
<!-- 4.
href
target
-->
<a href="http://www.baidu.com" target="_blank"> </a>
<!-- , -->
<a name="top"> </a>
<h1>18518518515</h1>
<h1>123</h1>
<h1>123</h1>
<h1>123</h1>
<h1>123</h1>
<h1>123</h1>
<h1>123</h1>
<h1>123</h1>
<h1>123</h1>
<h1>123</h1>
<h1>123</h1>
<!-- href , # name -->
<a href="#top"> , </a>
<!-- 5. input -->
<br />
<input type="text" /> <!-- -->
<input type="number" /> <!-- -->
<input type="password" /> <!-- , -->
<input type="date" /> <!-- -->
<input type="week" /> <!-- -->
<input type="radio" /> <!-- -->
<input type="checkbox" /> <!-- -->
<input type="button" value=" "/> <!-- -->
<input type="submit" /> <!-- -->
<br /><br /><br /><br /><br /><br />
</body>
</html>
총결산이 글 은 여기까지 입 니 다.당신 에 게 도움 을 줄 수 있 기 를 바 랍 니 다.또한 당신 이 우리 의 더 많은 내용 에 관심 을 가 져 주 실 수 있 기 를 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JPA + QueryDSL 계층형 댓글, 대댓글 구현(2)이번엔 전편에 이어서 계층형 댓글, 대댓글을 다시 리팩토링해볼 예정이다. 이전 게시글에서는 계층형 댓글, 대댓글을 구현은 되었지만 N+1 문제가 있었다. 이번에는 그 N+1 문제를 해결해 볼 것이다. 위의 로직은 이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.