Skip to content

Tag: jdbc

what databases can be used with java?

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…

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 …

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…