forked from mobbeitan/WF-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSQLInjectionExample.java
More file actions
22 lines (19 loc) · 827 Bytes
/
SQLInjectionExample.java
File metadata and controls
22 lines (19 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class SQLInjectionExample extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db");
String query = "SELECT * FROM users WHERE username = '" + request.getParameter("username") + "';";
Statement stmt = con.createStatement();
stmt.executeQuery(query);
} catch (Exception e) {
throw new ServletException(e);
}
}
}