Answers for "A bad way of running a SQL query in JDBC"

0

A bad way of running a SQL query in JDBC

// The user we want to find.
String email = "[email protected]";

// Connect to the database.
Connection conn = DriverManager.getConnection(URL, USER, PASS);
Statement stmt = conn.createStatement();

// Bad, bad news! Don't construct the query with string concatenation.
String sql = "SELECT * FROM users WHERE email = '" + email + "'";

// I have a bad feeling about this...
ResultSet results = stmt.executeQuery(sql);

while (results.next()) {
  // ...oh look, we got hacked.
}
Posted by: Guest on October-01-2021

Browse Popular Code Answers by Language