JDBC Section Index | Page 3
What's the difference between a transient and non-transient exception?
Subclasses of SQLException have two types, transient and non-transient.
Transient exceptions are those that when retried could succeed without changing anything.
Non-transient exceptions are tho...more
Using Java 6, how do you loop through the causes of a SQL Exception?
The SQLException class is now Iterable in Java 6.
try {
...
} catch (SQLException sqle) {
for(Throwable t : sqle) {
System.out.println("Throwable: " + t);
}
}
more
How do I loop through the causes of a SQL Exception?
You can repeatedly call getCause() of the SQLException:
try {
...
} catch (SQLException sqle) {
for(Throwable t : sqle) {
System.out.println("Throwable: " + t);
Throwable cause = t...more
How do I loop through all the causes of a SQLException?
You can call the getCause() method of the exception repeatedly
try {
...
} catch (SQLException sqle) {
for(Throwable t : sqle) {
System.out.println("Throwable: " + t);
Throwable ca...more
How do I load a database driver with JDBC 4.0 / Java 6?
Provided the JAR file containing the driver is properly configured, just place the JAR file in the classpath. That's it. No need to manually load the class or register the driver.
For loading and registering a driver you should use Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"), but I have used JdbcOdbcDriver j=new JdbcOdbcDriver() and I still get a connection. Why is this so? Why should I use Class.forName("");
For loading and registering a driver you should use Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"), but I have used JdbcOdbcDriver j=new JdbcOdbcDriver() and I still get a connection. Why is this s...more
How do I insert a .jpg into a mySQL data base? I have tried inserting the file as byte[], but I recieve an error message stating that the syntax is incorrect.
How do I insert a .jpg into a mySQL data base? I have tried inserting the file as byte[], but I recieve an error message stating that the syntax is incorrect.
- David Bennet
What is the best way to generate a universally unique object ID? Do I need to use an external resource like a file or database, or can I do it all in memory?
[I need to generate unique id's that will be used for node 'ID' attribute values within XML documents. This id must be unique system-wide. The generator must be available to a number of servlets t...more
Whan happens when I close a Connection application obtained from a connection Pool? How does a connection pool maintain the Connections that I had closed through the application?
It is the magic of polymorphism, and of Java interface vs. implementation types. Two objects can both be "instanceof" the same interface type, even though they are not of the same implem...more
How can I know when I reach the last record in a table, since JDBC doesn't provide an EOF method?
You can use
last()
method of java.sql.ResultSet, if you make it scrollable.
Joe Sam Shirah adds: You can also use isLast() as you are reading the ResultSet.
One thing to keep in mind, though, is...more
Problem with getDouble()
Problem with getDouble()
We use the Java method getDouble() to get numeric values. Up to now it worked properly but suddenly we got false values, like 49066.429000000004 for the true value 49066.4...more
How can I correctly parse CSV ( comma separated values ) files? StringTokenizer doesn't seem to fit many conditions.
Ian Darwin has two classes ( CSV.java and CSVRE.java ) to handle CSV files in his Java Cookbook, including a way with regular expressions. You can download the code from his site, probably best t...more
Where can I find info, frameworks and example source for writing a JDBC driver?
There a several drivers with source available, like MM.MySQL, SimpleText Database, FreeTDS, and RmiJdbc. There is at least one free framework, the jxDBCon-Open Source JDBC driver framework. Any...more
Is any JDBC driver available that can access EDI messages?
I don't know about existing drivers, but JavaPro had a good article on writing your own driver. The example was a driver to access XML files. check it out at JavaPro December, 2001.
Joe Sam Shira...more
How can I create a custom RowSetMetaData object from scratch?
One unfortunate aspect of RowSetMetaData for custom versions is that it is an interface. This means that implementations almost have to be proprietary. The JDBC RowSet package is the most common...more