I’m trying to use PreparedStatements for the first time, but for some reason I just cant get this to work. The same request made not using a PreparedStaement works fine.
The simple working version:
String artNum = "'" + artikelNummer.toLowerCase() + "'";
String query =
"SELECT a.artnr, a.bezeichnung, "
+ "(SELECT verfuegbar_bestand "
+ "FROM getbestand(a.uid)) AS bestand_verfuegbar "
+ "FROM article AS a "
+ "WHERE lower(a.artnr) = " + artNum;
ResultSet results = statement.executeQuery(query);
The PreparedStatement version:
String artNum = "'" + artikelNummer.toLowerCase() + "'";
String query =
"SELECT a.artnr, a.bezeichnung, "
+ "(SELECT verfuegbar_bestand "
+ "FROM getbestand(a.uid)) AS bestand_verfuegbar "
+ "FROM article AS a "
+ "WHERE lower(a.artnr) = ? ";
prepStatement = con.prepareStatement(query);
prepStatement.setString(1, artNum);
ResultSet results = prepStatement.executeQuery();
Any help/ideas would be very greatfully received.
Ps Yes artNum is a String not an int eg A1110
If you’re using PreparedStatements, you don’t need to enclose the string in quotes like this:
This needs to be :