Board index » jbuilder » Can't Save SQLServer VarChar

Can't Save SQLServer VarChar


2004-02-03 10:35:23 AM
jbuilder0
I have simple one table/one field add/edit/delete example. If the field type
is char, everything is fine, but a soon as I change it to varchar, saving
changes to a row throws an exception. I've included the stack trace, but
basically the resolver is calling getBigDecimal, for no reason that I can
imagine. I'll post the code as well if would help, but like I said, it's a
dirt simple example. Thanks.
BTW, this was a working application that suddenly started with this
behavior. I know it has to be related to some recent change in the
environment (not the code since this happens even on a simple example), but
I can't fathom what the change might be.
JBuilder 9 Developer -- WinXPSP1 || Win2KSP4 -- SQLServer2K
-Steve
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseData.getBigDecimal(Unknown Source)
at com.microsoft.jdbc.base.BaseData.getBigDecimal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.setObjectInternal(Unknown
Source)
at com.microsoft.jdbc.base.BasePreparedStatement.setObject(Unknown Source)
at com.borland.dx.sql.dataset.j.setParameter(Unknown Source)
at com.borland.dx.sql.dataset.a.a(Unknown Source)
at com.borland.dx.sql.dataset.l.a(Unknown Source)
at com.borland.dx.sql.dataset.QueryResolver.updateRow(Unknown Source)
at com.borland.dx.sql.dataset.ResolutionManager.a(Unknown Source)
at com.borland.dx.sql.dataset.ResolutionManager.e(Unknown Source)
at com.borland.dx.sql.dataset.ResolutionManager.e(Unknown Source)
at com.borland.dx.sql.dataset.ResolutionManager.saveChanges(Unknown Source)
at com.borland.dx.sql.dataset.ResolutionManager.saveChanges(Unknown Source)
at com.borland.dx.sql.dataset.Database.saveChanges(Unknown Source)
at com.borland.dx.sql.dataset.QueryDataSet.saveChanges(Unknown Source)
at com.borland.dx.dataset.DataSet.saveChanges(Unknown Source)
at
com.borland.dbswing.JdbNavToolBar.actionPerformed(JdbNavToolBar.java:1804)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(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.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(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.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
 
 

Re:Can't Save SQLServer VarChar

It only gets more bizarre: If the underlying field is VARCHAR, but you call
setSqlType(1), which is CHAR, it works fine. But if you setSqlType(12),
which is VARCHAR, what it should be, it tanks. How much sense does that
make? I'd be happy to change all my setSqlType calls if only I knew why it
suddenly started working this way and if the workaround is safe.
BTW, I tried a different SQL Server JDBC driver and got a completely
different error, but in the same place, so that whole getBigDecimal thing is
spurious, I guess.
Here's the code:
database1.setConnection(new
com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://
server:1433", "username", "username", false,
"com.microsoft.jdbc.sqlserver.SQLServerDriver"));
queryDataSet1.setMetaDataUpdate(MetaDataUpdate.TABLENAME+MetaDataUpdate.PREC
ISION+MetaDataUpdate.SCALE+MetaDataUpdate.SEARCHABLE);
queryDataSet1.setQuery(new
com.borland.dx.sql.dataset.QueryDescriptor(database1, "SELECT t1.f1 FROM
TEST.dbo.t1", null, true, Load.ALL));
column1.setCaption("Blat");
column1.setColumnName("t1");
column1.setDataType(com.borland.dx.dataset.Variant.STRING);
column1.setPrecision(10);
column1.setRowId(true);
column1.setSchemaName("dbo");
column1.setTableName("t1");
column1.setServerColumnName("f1");
column1.setSqlType(1); // Try changing
this to 12
queryDataSet1.setColumns(new Column[] {column1});
queryDataSet1.open();
queryDataSet1.setString("f1", "blat");
queryDataSet1.saveChanges();
"Nobody" < XXXX@XXXXX.COM >wrote in message
Quote
I have simple one table/one field add/edit/delete example. If the field
type
is char, everything is fine, but a soon as I change it to varchar, saving
changes to a row throws an exception. I've included the stack trace, but
basically the resolver is calling getBigDecimal, for no reason that I can
imagine. I'll post the code as well if would help, but like I said, it's a
dirt simple example. Thanks.

BTW, this was a working application that suddenly started with this
behavior. I know it has to be related to some recent change in the
environment (not the code since this happens even on a simple example),
but
I can't fathom what the change might be.

JBuilder 9 Developer -- WinXPSP1 || Win2KSP4 -- SQLServer2K

-Steve
--
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Value
can
not be converted to requested type.

at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

at com.microsoft.jdbc.base.BaseData.getBigDecimal(Unknown Source)

at com.microsoft.jdbc.base.BaseData.getBigDecimal(Unknown Source)

at
com.microsoft.jdbc.base.BasePreparedStatement.setObjectInternal(Unknown
Source)

at com.microsoft.jdbc.base.BasePreparedStatement.setObject(Unknown
Source)

at com.borland.dx.sql.dataset.j.setParameter(Unknown Source)

at com.borland.dx.sql.dataset.a.a(Unknown Source)

at com.borland.dx.sql.dataset.l.a(Unknown Source)

at com.borland.dx.sql.dataset.QueryResolver.updateRow(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.a(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.e(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.e(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.saveChanges(Unknown
Source)

at com.borland.dx.sql.dataset.ResolutionManager.saveChanges(Unknown
Source)

at com.borland.dx.sql.dataset.Database.saveChanges(Unknown Source)

at com.borland.dx.sql.dataset.QueryDataSet.saveChanges(Unknown Source)

at com.borland.dx.dataset.DataSet.saveChanges(Unknown Source)

at
com.borland.dbswing.JdbNavToolBar.actionPerformed(JdbNavToolBar.java:1804)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(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.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(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.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)



 

Re:Can't Save SQLServer VarChar

Can you say "JDBC driver service pack"? Just kill me now, please.
"Steve" < XXXX@XXXXX.COM >wrote in message
Quote
It only gets more bizarre: If the underlying field is VARCHAR, but you
call
setSqlType(1), which is CHAR, it works fine. But if you setSqlType(12),
which is VARCHAR, what it should be, it tanks. How much sense does that
make? I'd be happy to change all my setSqlType calls if only I knew why it
suddenly started working this way and if the workaround is safe.

BTW, I tried a different SQL Server JDBC driver and got a completely
different error, but in the same place, so that whole getBigDecimal thing
is
spurious, I guess.

Here's the code:

database1.setConnection(new

com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://
server:1433", "username", "username", false,
"com.microsoft.jdbc.sqlserver.SQLServerDriver"));


queryDataSet1.setMetaDataUpdate(MetaDataUpdate.TABLENAME+MetaDataUpdate.PREC
ISION+MetaDataUpdate.SCALE+MetaDataUpdate.SEARCHABLE);
queryDataSet1.setQuery(new
com.borland.dx.sql.dataset.QueryDescriptor(database1, "SELECT t1.f1 FROM
TEST.dbo.t1", null, true, Load.ALL));
column1.setCaption("Blat");
column1.setColumnName("t1");
column1.setDataType(com.borland.dx.dataset.Variant.STRING);
column1.setPrecision(10);
column1.setRowId(true);
column1.setSchemaName("dbo");
column1.setTableName("t1");
column1.setServerColumnName("f1");
column1.setSqlType(1); // Try changing
this to 12
queryDataSet1.setColumns(new Column[] {column1});
queryDataSet1.open();
queryDataSet1.setString("f1", "blat");
queryDataSet1.saveChanges();



"Nobody" < XXXX@XXXXX.COM >wrote in message
news:401f08eb$ XXXX@XXXXX.COM ...
>I have simple one table/one field add/edit/delete example. If the field
type
>is char, everything is fine, but a soon as I change it to varchar,
saving
>changes to a row throws an exception. I've included the stack trace, but
>basically the resolver is calling getBigDecimal, for no reason that I
can
>imagine. I'll post the code as well if would help, but like I said, it's
a
>dirt simple example. Thanks.
>
>BTW, this was a working application that suddenly started with this
>behavior. I know it has to be related to some recent change in the
>environment (not the code since this happens even on a simple example),
but
>I can't fathom what the change might be.
>
>JBuilder 9 Developer -- WinXPSP1 || Win2KSP4 -- SQLServer2K
>
>-Steve
>--
>java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Value
can
>not be converted to requested type.
>
>at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown
Source)
>
>at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
>
>at com.microsoft.jdbc.base.BaseData.getBigDecimal(Unknown Source)
>
>at com.microsoft.jdbc.base.BaseData.getBigDecimal(Unknown Source)
>
>at
com.microsoft.jdbc.base.BasePreparedStatement.setObjectInternal(Unknown
>Source)
>
>at com.microsoft.jdbc.base.BasePreparedStatement.setObject(Unknown
Source)
>
>at com.borland.dx.sql.dataset.j.setParameter(Unknown Source)
>
>at com.borland.dx.sql.dataset.a.a(Unknown Source)
>
>at com.borland.dx.sql.dataset.l.a(Unknown Source)
>
>at com.borland.dx.sql.dataset.QueryResolver.updateRow(Unknown Source)
>
>at com.borland.dx.sql.dataset.ResolutionManager.a(Unknown Source)
>
>at com.borland.dx.sql.dataset.ResolutionManager.e(Unknown Source)
>
>at com.borland.dx.sql.dataset.ResolutionManager.e(Unknown Source)
>
>at com.borland.dx.sql.dataset.ResolutionManager.saveChanges(Unknown
Source)
>
>at com.borland.dx.sql.dataset.ResolutionManager.saveChanges(Unknown
Source)
>
>at com.borland.dx.sql.dataset.Database.saveChanges(Unknown Source)
>
>at com.borland.dx.sql.dataset.QueryDataSet.saveChanges(Unknown Source)
>
>at com.borland.dx.dataset.DataSet.saveChanges(Unknown Source)
>
>at
>
com.borland.dbswing.JdbNavToolBar.actionPerformed(JdbNavToolBar.java:1804)
>
>at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
>
>at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
>Source)
>
>at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
>
>at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
>
>at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source)
>
>at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
>
>at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
>
>at java.awt.Component.processMouseEvent(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.LightweightDispatcher.retargetMouseEvent(Unknown Source)
>
>at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
>
>at java.awt.LightweightDispatcher.dispatchEvent(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.dispatchEvent(Unknown Source)
>
>at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
>
>
>


 

{smallsort}

Re:Can't Save SQLServer VarChar

what is the type of the column (in querydataset) that corresponds to the
varchar field?
Nobody wrote:
Quote
I have simple one table/one field add/edit/delete example. If the field type
is char, everything is fine, but a soon as I change it to varchar, saving
changes to a row throws an exception. I've included the stack trace, but
basically the resolver is calling getBigDecimal, for no reason that I can
imagine. I'll post the code as well if would help, but like I said, it's a
dirt simple example. Thanks.

BTW, this was a working application that suddenly started with this
behavior. I know it has to be related to some recent change in the
environment (not the code since this happens even on a simple example), but
I can't fathom what the change might be.

JBuilder 9 Developer -- WinXPSP1 || Win2KSP4 -- SQLServer2K

-Steve
--
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Value can
not be converted to requested type.

at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

at com.microsoft.jdbc.base.BaseData.getBigDecimal(Unknown Source)

at com.microsoft.jdbc.base.BaseData.getBigDecimal(Unknown Source)

at com.microsoft.jdbc.base.BasePreparedStatement.setObjectInternal(Unknown
Source)

at com.microsoft.jdbc.base.BasePreparedStatement.setObject(Unknown Source)

at com.borland.dx.sql.dataset.j.setParameter(Unknown Source)

at com.borland.dx.sql.dataset.a.a(Unknown Source)

at com.borland.dx.sql.dataset.l.a(Unknown Source)

at com.borland.dx.sql.dataset.QueryResolver.updateRow(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.a(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.e(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.e(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.saveChanges(Unknown Source)

at com.borland.dx.sql.dataset.ResolutionManager.saveChanges(Unknown Source)

at com.borland.dx.sql.dataset.Database.saveChanges(Unknown Source)

at com.borland.dx.sql.dataset.QueryDataSet.saveChanges(Unknown Source)

at com.borland.dx.dataset.DataSet.saveChanges(Unknown Source)

at
com.borland.dbswing.JdbNavToolBar.actionPerformed(JdbNavToolBar.java:1804)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(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.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(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.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)



 

Re:Can't Save SQLServer VarChar

Fadi Mujahid wrote:
Quote
what is the type of the column (in querydataset) that corresponds to the
varchar field?

QueryDataSet.getString() usually, but I do not use MS-SQL and have not in a
very long time. If that does not work, try something like:
Variant v= new Variant();
yourQueryDataSet.getVariant("NAME",v);
v.toString();
P.S. I have no idea if this will work for you.