Errormessages from database

I would like to know how I can show an error that is triggered by the database. I have the following coding:

_success = forms[_form].controller.saveData();
if (_success == false)
{
	_errormessage = ServoyException.getMessage();
	
	databaseManager.rollbackTransaction();	
	if 	(_errormessage == '')
		plugins.dialogs.showErrorDialog('Save record', 'Due to database restictions the record could not be saved','OK');
	else
		plugins.dialogs.showErrorDialog('Save record', _errormessage,'OK');	
	return -1;
}

If _success variabele is false, then the _errormessage variable contains ‘Unknown error’. Perhaps I need to get the errormessage in another way. Is there someone who can tell me how?

I also tried the following

_errormessage = databaseManager.getLastDatabaseMessage();

but now _errormessage remains empty even when there was an error from the database

I’m using Servoy 3.5 with SQL Server 2005

Thanks for your reply

Martin

I still have this problem. Doesn’t anyone else has same problem that errors from the (SQL Server) database are not shown in the application?

I also noticed that the errorhandler is not triggered

2007-11-12 10:41 AWT-EventQueue-0 ERROR com.servoy.j2db.util.Debug Throwable 
java.sql.SQLException: Cannot insert duplicate key row in object 'dbo.articlemaingroup' with unique index 'IX_acticlemaingroup_code'. 
     at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364) 
     at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2754) 
     at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2195) 
     at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:620) 
     at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:483) 
     at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:445) 
     at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:402) 
     at sun.reflect.GeneratedMethodAccessor331.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
     at java.lang.reflect.Method.invoke(Unknown Source) 
     at com.servoy.j2db.persistence.datasource.p.invoke(Unknown Source) 
     at $Proxy0.executeUpdate(Unknown Source) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at com.servoy.j2db.dataprocessing.SQLEngine.performUpdates(Unknown Source) 
     at com.servoy.j2db.dataprocessing.aa.do(Unknown Source) 
     at com.servoy.j2db.FormController$JSForm.js_saveData(Unknown Source) 
     at inv9.invoke() 
     at org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:550) 
     at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:466) 
     at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1254) 
     at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2031) 
     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94) 
     at com.servoy.j2db.scripting.e.call(Unknown Source) 
     at com.servoy.j2db.develop.debugger.k.a(Unknown Source) 
     at com.servoy.j2db.develop.debugger.k.executeFunction(Unknown Source) 
     at com.servoy.j2db.FormController.a(Unknown Source) 
     at com.servoy.j2db.FormController.executeFunction(Unknown Source) 
     at com.servoy.j2db.FormController.actionPerformed(Unknown Source) 
     at com.servoy.j2db.FormController$a.actionPerformed(Unknown Source) 
     at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
     at javax.swing.AbstractButton$Handler.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.Component.processMouseEvent(Unknown Source) 
     at javax.swing.JComponent.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.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)

I created a case, but am I the only one with this kind of problem?

Martin,

Have a look at databaseManager.getFailedRecords():

//Get the failed records after a save
var array = databaseManager.getFailedRecords()
for( var i = 0 ; i < array.length ; i++ )
{
	var record = array[i];
	application.output(record.exception);
}

Note that on calling saveData, Servoy will try to save all outstanding data.
If one record failed, the remaining outstanding records will still be attempted to be saved so you can end up with multiple failed records.

Rob

Hi Rob,

Your coding shows the error:

% _record.exception
com.servoy.j2db.dataprocessing.DataException: Cannot insert duplicate key row in object 'dbo.articlemaingroup' with unique index 'IX_acticlemaingroup_code'.
% _record.exception.getMessage()
Cannot insert duplicate key row in object 'dbo.articlemaingroup' with unique index 'IX_acticlemaingroup_code'.
% _record.exception.getErrorCode()
100
% _record.exception.isDataException()
true
%

But it doesn’t trigger the OnError method. Is that correct, so that I have to call the errorhandler myself?

_success = forms[_form].controller.saveData();
if (_success == false)
{
	//Get the failed records after a save 
	var _array = databaseManager.getFailedRecords() ;
	for( var i = 0 ; i < _array.length ; i++ ) 
	{ 
	   var _record = _array[i]; 
	   application.output(_record.exception); 
	   globals.my_errorHandler(_record.exception);
	} 
}

Where my_errorHandler is the same global method as used in the solution settings for the OnError method.