I’ve been working on a SQL utility and I am trying to set the parameters inside a prepared statement in multiple functions. To lessen the code, I have a function that returns a prepared statement where all the params are set. My question is: Does the connection reference in the configureStatement() get closed using the try with resources in the
Tag: prepared-statement
Should I close the prepared statement passed as parameter?
I am aware that we should not reuse prepared statement or use try-with-resource in java. But what should I do with prepared statement passed as parameter? Should I close it too? For example: Answer The way I see it is as follows: In your code somemethod is not the owner of those prepared statements that were passed to it. It
Java PreparedStatement preserve table name casing
I have this Java snippet, running inside a WildFly server backed by MariaDB: which gives me the following exception: So, apparentally, it decided to uppercase the table name, which I don’t want. How can I turn it off? Answer That is not possible, SQL dialects are – usually – case insensitive by default, but store the table name in uppercase
Java: Insert multiple rows into MySQL with PreparedStatement
I want to insert multiple rows into a MySQL table at once using Java. The number of rows is dynamic. In the past I was doing… I’d like to optimize this to use the MySQL-supported syntax: but with a PreparedStatement I don’t know of any way to do this since I don’t know beforehand how many elements array will contain.
PreparedStatement setNull(..)
Java PreparedStatement provides a possibility to explicitely set a Null value. This possibility is: Are the semantics of this call the same as when using a specific setType with a null parameter? ? Answer This guide says: 6.1.5 Sending JDBC NULL as an IN parameter The setNull method allows a programmer to send a JDBC NULL (a generic SQL NULL)
Using Prepared Statements to set Table Name
I’m trying to use prepared statements to set a table name to select data from, but I keep getting an error when I execute the query. The error and sample code is displayed below. Any thoughts on what might be causing this? Answer A table name can’t be used as a parameter. It must be hard coded. So you can