Skip to content

Add some different vectors to HSQL example #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hsql/src/Register.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
pst.setString(3, phone);
int i=pst.executeUpdate();
out.write(i+" records inserted, <a href='ViewRecords?name=" + name + "'>View Records</a>");
out.write("</br><a href='test.html'>View Tests</a>");
} catch (SQLException e) {
throw new ServletException(e);
}
Expand Down
16 changes: 14 additions & 2 deletions hsql/src/ViewRecords.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

public class ViewRecords extends HttpServlet {
Connection con;
HashMap methods;
@Override
public void init() throws ServletException {
try {
Expand All @@ -26,13 +28,23 @@ public void init() throws ServletException {
} catch (SQLException e) {
e.printStackTrace(System.out);
}

methods = new HashMap<String,String>();
methods.put("str", "select * from contacts where name='%s'");
methods.put("int_groupby", "SELECT * FROM contacts GROUP BY %s");
methods.put("int_orderby", "SELECT * FROM contacts ORDER BY %s");
methods.put("int_inline", "%s");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
try {
String name = request.getParameter("name");
ResultSet rs =con.createStatement().executeQuery("select * from contacts where name='" + name + "'");
String inject = request.getParameter("inject");
String method = request.getParameter("method");

String query = String.format((String)methods.get(method), inject);

ResultSet rs =con.createStatement().executeQuery(query);
while(rs.next()){
out.write("<br/>"+rs.getString(1));
out.write(", "+rs.getString(2));
Expand Down
23 changes: 23 additions & 0 deletions hsql/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Injection Tests</title>
</head>
<body>
<form method = "get" action = "ViewRecords">
Inject<br/>
<input type = "text" name = "inject"/>
<br/>
Method<br/>
<select name="method">
<option value="str">str</option>
<option value="int_groupby">int_groupby</option>
<option value="int_orderby">int_orderby</option>
<option value="int_inline">int_inline</option>
</select>
<br/>
<input type = "submit" values = "Submit"/>
</form>
</body>
</html>