• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

ResultSet Data Manipulation

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
My System
Linux - Debian 3.0 - Kernel 2.4.25
Windows XP
mySQl
MS Access
Java 1.4.2_02
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karel.
The way I have approached this in the past (and I'm not sure whether it's a good way or not to be honest perhaps others will comment ) is to create my own class to wrap the ResultSet up and hence keep it after the DB connection has been closed.
I have something along the lines of:

The two Vector arguments to the constructor are taken from the genuine ResultSet object before it is closed.
Hope this helps a little
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and, I forgot this, which is how I populate those two Vectors that are passed to MyDBResults
 
Karel Young
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have thought about using Vectors but If possible I want to avoid using them for the DB implementation
I prefer the way the the ResultSet interface works and it also shortens some of the code by some quite large amounts
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fair point. I'd be interested to see what else comes out of this thread myself as I could also use a more elegant solution to this ResultSet being closed problem.
 
author
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at iBATIS SQL Maps.
 
Karel Young
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking around on the Sun WebSite (Which is hard as 50% odd is down) it looks like they are creating a CachedRowSet Class which extends RowSet which in turn extends Resultset and gives the result I am looking for.
But although there are indications that you get get a copy of it off the web site (with Registration) there is actually no links to the Class itself.
I am doing a lot of hunting around at the moment to see what I can find.
 
Karel Young
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
For my next trick, I'll need the help of a tiny ad ...
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic