Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
3 Cards in this Set
- Front
- Back
How string which is put to PreparedStatement with setString() method will look like in query? What is danger zone of that? |
String will be put with quotes: 'string' It to put such string as name of column - that will cause syntax error. Column name must be without quotes. |
|
What is the reason of PSQLException: ERROR: syntax error at or near “$1? How to avoid that? |
When using the type 'string' syntax as in timestamp '2014-11-11 -05:00:00', the value provided must be a constant, not a parameter. It's interpreted and converted to an internal timestamp representation by the SQL engine at the parse stage, before actual execution takes place and before the values for the parameters are known. So when encountering timestamp $1, the parser produces a syntax error because $1 is not a literal string. On the other hand, the value of cast($1 as timestamp) will be produced at execute stage, so this is what should be used. My way: Statement stmt = db.createStatement(); stmt.execute(preparedStmt.toString); |
|
Как создать экземпляр класса по его int id, зная его id и class? Мы знаем, что у этого класса есть конструктор, который принимает int id |
Constructor constructor = class.getConstructor(Integer.class); MyClass instance = constructor.newInstance(id); |