I am doing an undergrad final project, and need to justify my choice of MySQL for the database element of my project. Truth is, it’s the only one I can really use, and hence I went for it. What other database systems could I have used? Any advantages and disadvantages of these over MySQL? Answer In fact…
Tag: jdbc
How to quote/escape identifiers such as column names with JDBC?
Different database servers use different ways to quote and escape identifiers. E.g. “foo bar” vs `foo bar` vs [foo bar], or “10””” vs “10””, or identifiers such as FooBar or array need to be quoted for some databases but not for others. Is there any API me…
How to catch a specific exception in JDBC?
How to catch specific exceptions in JDBC? Examples: primary key exception or foreign key exception. Answer SQLException contains some database-specific info related to the exception. From the doc: Each SQLException provides several kinds of information: 1) a string describing the error. This is used as the Ja…
Cannot issue data manipulation statements with executeQuery()
In MySQL I have two tables, tableA and tableB. I am trying to execute two queries: But I get the following error: What does this mean? Answer To manipulate data you actually need executeUpdate() rather than executeQuery(). Here’s an extract from the executeUpdate() javadoc which is already an answer at …
What are all the possible values for SQLException.getSQLState?
SQLException.getSQLState retrieves the SQLState for the SQLException object. What are all the possible values that can be returned by this method? Can I use the value to identify specific errors that occurred in the database (i.e. can this value tell me if it was a PK violation, or a unique constraint, or col…
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 sen…
How do I manually configure a DataSource in Java?
I’m trying to follow Sun’s JDBC tutorial at http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html It gives the following example code: This code doesn’t compile because the DataSource interface has none of these methods, except for the getConnection() method invoked last. (Here…
ResultSet: Retrieving column values by index versus retrieving by label
When using JDBC, I often come across constructs like I asked myself (and authors of code too) why not to use labels for retrieving column values: The best explanation I’ve heard is something concerning performance. But actually, does it make processing extremely fast? I don’t believe so, though I …