• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Show Tables In MSSQL

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic