databasemanager question

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

databasemanager question

Postby RobertMeyer » Fri Feb 27, 2004 12:08 am

is there a way to tell if an sql lookup via databasemanager.getDataSetByQuery
worked?

i realize that if it works, it returns a JDataSet object;
what does it return if the lookup fails?
RobertMeyer
 
Posts: 268
Joined: Sat Dec 27, 2003 9:05 pm

Postby IT2Be » Fri Feb 27, 2004 9:50 am

It will return null...
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby RobertMeyer » Sat Feb 28, 2004 6:02 pm

oh! i didn't think of that!

thanks.
RobertMeyer
 
Posts: 268
Joined: Sat Dec 27, 2003 9:05 pm

Postby RobertMeyer » Sat Feb 28, 2004 10:00 pm

actually, i just tested that, and it's not correct.

i have a query with a typo in it, and the result from
the databaseManager (as viewed in the debugger window)
is something like "java.sql.SQLException..."

does anyone know how to test for that?
RobertMeyer
 
Posts: 268
Joined: Sat Dec 27, 2003 9:05 pm

Postby maarten » Sun Feb 29, 2004 11:08 am

testing if dataset has data:
if(dataset.getMaxRowIndex()>0 )
{
//go ahead
}
else
{
//error message
}


If you highlight the line in the debugger window you can copy paste it into a text editor

You can also use following code to capture the error into a variable.

Code: Select all
application.setErrorCapture(true)
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
var errorText = application.getLastErrorCode()

...or make it show up in the output window of the debugger:
Code: Select all
application.output(errorText)
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby maarten » Mon Mar 01, 2004 9:32 pm

replace this code...
Code: Select all
application.setErrorCapture(true)
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
var errorText = application.getLastErrorCode()


with this...
Code: Select all
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
var errorText = dataset.getExceptionMsg()
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 11 guests