2021-09-16 18:12:24 +03:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,kotlin]
|
2021-09-16 18:12:24 +03:00
|
|
|
----
|
|
|
|
val ps: PreparedStatement = con.prepareStatement("SELECT fname, lname FROM employees where hireDate > ? and salary < ?")
|
|
|
|
ps.setDate(0, date) // Noncompliant
|
|
|
|
ps.setDouble(3, salary) // Noncompliant
|
|
|
|
|
|
|
|
val rs: ResultSet = ps.executeQuery()
|
|
|
|
while (rs.next()) {
|
|
|
|
val fname: String = rs.getString(0) // Noncompliant
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,kotlin]
|
2021-09-16 18:12:24 +03:00
|
|
|
----
|
|
|
|
val ps: PreparedStatement = con.prepareStatement("SELECT fname, lname FROM employees where hireDate > ? and salary < ?")
|
|
|
|
ps.setDate(1, date)
|
|
|
|
ps.setDouble(2, salary)
|
|
|
|
|
|
|
|
val rs: ResultSet = ps.executeQuery()
|
|
|
|
while (rs.next()) {
|
|
|
|
val fname: String = rs.getString(1)
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
|