JDBC | Unable to update the result set through a JTable

Database
Enthusiast

JDBC | Unable to update the result set through a JTable

Hi,
when I try to update the updatable result set returned by a query through a stand alone Java application, an error is caught.
The same update algorithm updates Oracle, MySQL and SQL Server databases successfully.

Here the obtained stack trace:

com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata JDBC Driver] [TeraJDBC 13.10.00.18] [Error 1244] [SQLState HY000] Column index value 0 is outside the valid range of 1 through 51
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:93)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:73)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:101)
at com.teradata.jdbc.jdbc_4.ResultSetRow.getValue(ResultSetRow.java:53)
at com.teradata.jdbc.jdbc_4.TDResultSet.getObjectFromCurrentRow(TDResultSet.java:185)
at com.teradata.jdbc.jdbc_4.TDResultSet.internalGetObject(TDResultSet.java:2028)
at com.teradata.jdbc.jdbc_4.TDResultSet.getObject(TDResultSet.java:2013)
at com.teradata.jdbc.jdbc_4.ResultSetUpdater.generateUpdateStatement(ResultSetUpdater.java:1534)
at com.teradata.jdbc.jdbc_4.ResultSetUpdater.updateRow(ResultSetUpdater.java:259)
at com.teradata.jdbc.jdbc_4.TDResultSet.updateRow(TDResultSet.java:850)
at net.sourceforge.open_teradata_viewer.ResultSetTable.editingStopped(ResultSetTable.java:207)
at javax.swing.AbstractCellEditor.fireEditingStopped(Unknown Source)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(Unknown Source)
at javax.swing.DefaultCellEditor.stopCellEditing(Unknown Source)
at javax.swing.JTable$GenericEditor.stopCellEditing(Unknown Source)
at javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(Unknown Source)
at javax.swing.JTextField.fireActionPerformed(Unknown Source)
at javax.swing.JTextField.postActionEvent(Unknown Source)
at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Open Teradata Viewer 0.06c (28/07/2011)
Windows XP 5.1 Service Pack 3 x86
Java(TM) SE Runtime Environment 1.6.0_24-b07
jdbc:teradata://../database=..,DBS_PORT=1025,CHARSET=UTF8,LOGMECH=LDAP,LOGDATA=..@@..
com.teradata.jdbc.TeraDriver
select * from EMP where NAME = 'JONES'

Here the Java code:

public final class ResultSetTable extends JTable {

...
...
...

@Override
public void editingStopped(ChangeEvent e) {
super.editingStopped(e);
ResultSet resultSet = Context.getInstance().getResultSet();
int column = getSelectedColumn();
Object value = null;
try {
int origRow = getOriginalSelectedRow();
resultSet.first();
resultSet.relative(origRow);
value = resultSet.getObject(column + 1);
if (value == null || !value.toString().equals(getTableValue())) {
String log = ("" + value).trim();
update(column + 1, getTableValue());
resultSet.updateRow();
value = resultSet.getObject(column + 1);
log += " -> " + ("" + resultSet.getObject(column + 1)).trim();
}
} catch (Throwable t) {
if (e == null) {
// explicitly invoked
throw new RuntimeException(t.getMessage(), t);
}
ExceptionDialog.showException(t);
} finally {
try {
if (value != null) {
setTableValue(value);
}
} catch (Exception e1) {
ExceptionDialog.hideException(e1);
}
}
}

...
...
...
}

Thanks in advance,
Daniel.
2 REPLIES
Enthusiast

Re: JDBC | Unable to update the result set through a JTable

It seems to work fine with version 14.00.00.01 JDBC driver.

Thanks!!

D.

Teradata Employee

Re: JDBC | Unable to update the result set through a JTable

This problem corresponds to:

JDBC DR 153226 Updatable ResultSet Error 1244 Column index value 0 is outside the valid range

which is fixed in Teradata JDBC Driver version 13.10.00.27 and later, as noted in the readme.txt.

Thank you for reporting the problem.

--Tom