38 lines
768 B
Plaintext
38 lines
768 B
Plaintext
== Why is this an issue?
|
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,kotlin]
|
|
----
|
|
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
|
|
|
|
[source,kotlin]
|
|
----
|
|
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)
|
|
// ...
|
|
}
|
|
----
|
|
|
|
|