34 lines
708 B
Plaintext
34 lines
708 B
Plaintext
![]() |
include::../description.adoc[]
|
||
|
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
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
|
||
|
|
||
|
----
|
||
|
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)
|
||
|
// ...
|
||
|
}
|
||
|
----
|
||
|
|
||
|
|