This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am creating a Java program that accesses a Database and so Far I have had no problems, but I have just realised that I need a "Multi-connect" architecture in my database rather than a perminant connection to the DataBase. I did some research and found that once I closed the Database Link my ResultSet (I am using this to hold the data rather than an Array/Vector) closed as well, after some hunting I found that I needed to change my PreparedStatement line to read --- PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM " + tbl, ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT); --- But when I try to run this command I get this Error --- Exception in thread "main" java.lang.UnsupportedOperationException at sun.jdbc.odbc.JdbcOdbcConnection.setHoldability(JdbcOdbcConnection.java:1698) ---
Apart from this my program is fully functional. If anyone can give me an idea on why I am getting this result/How to fix it. then I would appreciate it. (PS I want to avoid using Vectors or Arrays if I can as I have found that the Resultset is more efficient and can store more Data about the DB) My System Linux - Debian 3.0 - Kernel 2.4.25 Windows XP mySQl MS Access Java 1.4.2_02
1) Don't hang on to the ResultSet, use ArrayLists instead. They're a lot more efficient than are Vectors and don't hold on to database resources 2) you're using optional operations on the JDBC, which are likely not supported by the rather primitive JDBCODBC bridge driver. Use a real database instead like Firebird (http://firebird.sourceforge.net).
Joined: Mar 02, 2004
I have found that I can add a new Record to the Record set by using the InserRow() method but I am running into an interensting problem in that the Database has an AutoIncrement field as the ID and as a result I cannot write to that field without the program crashing. But I also cannot not write to the field because it throws an error. An unexpected exception has been detected in native code outside the VM. Unexpected Signal : 11 occurred at PC=0x4CD89AE3 Function=(null)+0x4CD89AE3 Library=/usr/lib/odbc/libmyodbc.so NOTE: We are unable to locate the function name symbol for the error just occurred. Please refer to release documentation for possible reason and solutions.
There is about 5 times that amount of error but the rest is a library trace. Any ideas?
Joined: Oct 12, 2000
Don't attempt to write the autoinc field! Write a new record, then read it back in to get the value of the field.
Joined: Mar 02, 2004
What I am wondering tho is how to crate the record using insertRow() without adding the Autoinc Field in there, I get an error when I do. If possible I want to avoid using strings to add the new record (that is what I am using at the moment and what I am trying to get away from) What I want ot be able to do is add a new record without having to commit the data first, I can edit a series of record and then commit them as a batch later on and I want to be able to do this with adding new records as well. (Without using arrays or vectors as I consider them to be a kludge ) Thanks for your help