Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Show Tables In MSSQL

 
Arthur Buliva
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arthur Buliva
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic