How to gettablenames of a serverconnection

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

How to gettablenames of a serverconnection

Postby tweetie » Thu Mar 11, 2004 10:15 pm

when I use
Code: Select all
var tableNamesArray =databaseManager.getTableNames('user_data');
var firstTableName = tableNamesArray[0];


I always get :
Code: Select all
[Ljava.lang.String;@fa3bb0
in tableNamesArray

I tried several existing database connections.
User avatar
tweetie
 
Posts: 345
Joined: Thu Jan 08, 2004 11:32 am
Location: Rotterdam, Netherlands

Postby jcompagner » Fri Mar 12, 2004 11:45 am

what doesn't work for you then?

Code: Select all
var tableNamesArray =databaseManager.getTableNames('user_data');
var firstTableName = tableNamesArray[0];
application.output(firstTableName)


gives me exactly the name of the first table found..
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby tweetie » Fri Mar 12, 2004 3:33 pm

In my case the output is null
and the tableNamesArray gives a
Code: Select all
[Ljava.lang.String;@9d6d87
as a result
User avatar
tweetie
 
Posts: 345
Joined: Thu Jan 08, 2004 11:32 am
Location: Rotterdam, Netherlands

Postby jcompagner » Fri Mar 12, 2004 3:39 pm

that's very strange then it looks like you have an empty array.. so no table name is returned..

do you have anything in the .log.txt file after you call it?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby jcompagner » Fri Mar 12, 2004 3:42 pm

if you test:

application.output(tableNamesArray[1]);

or

application.output(tableNamesArray.length);
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby tweetie » Fri Mar 12, 2004 3:43 pm

Never mind....
I restarted Servoy...
user_data has no tables and at first it returned null...and now it returns nothing.
Tried it with other connections and now it works....but yesterday it didn't...got some funny voodoo shit going on here :roll:

Either way....it's working now
User avatar
tweetie
 
Posts: 345
Joined: Thu Jan 08, 2004 11:32 am
Location: Rotterdam, Netherlands

Postby tweetie » Fri Mar 12, 2004 5:07 pm

Code: Select all
var TabelNaamArray = databaseManager.getTableNames(controller.getServerName());
var y=TabelNaamArray.getMaxRowIndex();
for (i=0;i<y;i++)
{
controller.newRecord();
tabellenid=TabelNaamArray[i];
}


TabelNaamArray gets all tablenames but I got an other problem:
The method stops dead in his tracks at line 2.
Isn't TabelNaamArray.getMaxRowIndex() the correct way to find out how many rows an array contains??
The error description:
Code: Select all
Java class "[Ljava.lang.String;" has no public instance field or method named "getMaxRowIndex".


In the log.txt it says:
Code: Select all
org.mozilla.javascript.EvaluatorException: Java class "[Ljava.lang.String;" has no public instance field or method named "getMaxRowIndex".org.mozilla.javascript.EvaluatorException: Java class "[Ljava.lang.String;" has no public instance field or method named "getMaxRowIndex".
User avatar
tweetie
 
Posts: 345
Joined: Thu Jan 08, 2004 11:32 am
Location: Rotterdam, Netherlands

Postby jcompagner » Sat Mar 13, 2004 1:20 am

please see example
it is an array what you get back to get the length of the array you have to do: array.length (so not getMaxRowIndex)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby tweetie » Sat Mar 13, 2004 12:58 pm

OK....it works...
but I'm confused...
I got this code somewhere from the forum:
Code: Select all
var Groups = security.getGroups();
var showArray = new Array(Groups.getMaxRowIndex());

for ( var i = 0 ; i < Groups.getMaxRowIndex() ; i++ )
showArray[i] = Groups.getValue(i + 1, 2);

I assumed that getGroups would also create an array. Obviously it is not an array. What is it then?
User avatar
tweetie
 
Posts: 345
Joined: Thu Jan 08, 2004 11:32 am
Location: Rotterdam, Netherlands

Postby jcompagner » Sat Mar 13, 2004 2:02 pm

i don't know why so many people are confused by this (you are not alone)
because it is so displayed as good as we can do it in the method editor..

if you select Security.getGroups() in youre editor.. what do you see in the status line? Of what does the tooltip of getGroups() say?

that it returns a JSDataSet.. for example if you go to JSDataSet self. (child of Security node, and you select getColumnAsArray() you see that that one returns an array (Object[])

JSDataSet can have multiple columns over many rows. And an array has one column.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby tweetie » Sat Mar 13, 2004 7:39 pm

Sorry....dude...
but hey what can I say...
do you read the manual of your VCR?? :lol:

I'm getting trained soon by one of you.....so I'll hope...no more dumb questions from me :shock:
User avatar
tweetie
 
Posts: 345
Joined: Thu Jan 08, 2004 11:32 am
Location: Rotterdam, Netherlands

Postby jcompagner » Sat Mar 13, 2004 9:45 pm

no problem (my reply wasn't meant to be aggressive in any way) but I was just stumped that many developers are mixing up an array and jsdataset.. :(

It's a question that comes up quite often..
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to How To

Who is online

Users browsing this forum: No registered users and 5 guests