aspose file tools*
The moose likes JDBC and the fly likes Show Tables In MSSQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Show Tables In MSSQL" Watch "Show Tables In MSSQL" New topic
Author

Show Tables In MSSQL

Arthur Buliva
Ranch Hand

Joined: Mar 08, 2006
Posts: 101
Hi friends. I am quite new to MSSQL as I have used MySQL intensively. But without whining much further, let me pour out my mind:



is a code that I want to use to connect to a MSSQL server and show tables in the database. This is what a sample run yields:



What could be the matter here?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You are trying to refer to an alias as a column. This:

is invalid. Try "TABLE_NAME" instead.


If you would rather try a better way, have a look at the methods provided by java.sql.DatabaseMetaData. This is the better way to do it, since now your code is portable. The downside is that not all Drivers will implement all the methods. However, you are using jTDS, which I think covers them all.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Arthur Buliva
Ranch Hand

Joined: Mar 08, 2006
Posts: 101
Thanks a lot. Worked so far. Will look at the DataBase meta data methods. So far this code works:


But the code



complains that



With all due respect to Microsoft, is it that they dont use the standard SQL syntax but rather decide to do it their own way?

And whats the way out?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Is DESCRIBE part of the ANSI standard? I didn't think it was; are you sure it is not an Oracle specific command MySQL have choosen to implement? As far as I am aware, MS SQL 2000 is ANSI-92 complient.

If you have lots of this meta data stuff to do, its probably quicker to swap to using DatabasMetaData. To build up simmilar output to how MySQL/Oracle's describe works is possible, but you'll have to do the work step by step, querying the system tables. Not quick.
[ December 03, 2007: Message edited by: Paul Sturrock ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Show Tables In MSSQL
 
Similar Threads
Connection over a web
hibernate caching problem
Why jar console program cannot run?
Enum representing DB table.
Date / Time problems