Re: describe table query?

Haris Peco <snpe@snpe.co.yu>

From: snpe <snpe@snpe.co.yu>
To: Dan Ostrowski <dan@triad-dev.com>
Cc: toastafari@yahoo.com, pgsql-general@postgresql.org
Date: 2002-09-10T02:21:03Z
Lists: pgsql-general
Hello,
	This is example.You see JDBC specification on sun.java.com
regards
import java.io.*;
import java.sql.*;
import java.text.*;

public class poruka
{
	Connection db;	

	public poruka(String driver,String url,String user,String passwd) throws 
ClassNotFoundException, FileNotFoundException, IOException, SQLException
	{
		Class.forName(driver);
		db = DriverManager.getConnection(url,user,passwd);
		DatabaseMetaData dbmd = db.getMetaData();
		
		
		ResultSet rs=dbmd.getTables(null,null,null,new String[] {"TABLE"});
		while (rs.next()) {
			String ime=rs.getString(1);
			System.out.print("1 " + ime + "  ");
			ime=rs.getString(2);
			System.out.print("2 " + ime + "  ");
			ime=rs.getString(3);
			System.out.print("3 " + ime + "  ");
			ime=rs.getString(4);
			System.out.print("4 " + ime + "  ");
			ime=rs.getString(5);
			System.out.print("5 " + ime + "  ");
			System.out.println();
		}


		db.close();
	}

	public static void main(String args[])
	{
		System.out.println("JDBC test \n");

		try
		{
			poruka test = new poruka(args[0],args[1],args[2],args[3]);
		}
		catch (Exception ex)
		{
			System.err.println("Exception caught.\n" + ex);
			ex.printStackTrace();
		}
	}
}

On Tuesday 10 September 2002 03:55 am, Dan Ostrowski wrote:
> I also would love to know how you do this,  because I am REALLY missing the
> "DESCRIBE <table>" calls...
>
> I work with mostly PHP4...
>
> please help!
>
> regards,
> dan
>
> On Tue, 10 Sep 2002 03:07:46 +0200
>
> snpe <snpe@snpe.co.yu> wrote:
> > If You use java then that is DatabaseMetaData.getColumns etc
> >
> > regards
> > Haris Peco
> >
> > On Monday 09 September 2002 11:30 pm, Andrew Bulmer wrote:
> > > I'm trying to write an Access clone in java that will
> > > use PostGres as a backend. Problem is, I need to be
> > > able to list all the fields (and data types) in a
> > > table. I know about "\d" but that only seems to work
> > > on the command line client (doesn't work if I pass it
> > > in as a query). I know in mysql DESCRIBE <table> will
> > > do it... is there an equivalent in postgres? I tried
> > > google but all I could find were references to the \d command.
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Yahoo! Finance - Get real-time stock quotes
> > > http://finance.yahoo.com
> > >
> > > ---------------------------(end of
> > > broadcast)--------------------------- TIP 2: you can get off all lists
> > > at once with the unregister command (send "unregister
> > > YourEmailAddressHere" to majordomo@postgresql.org)
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/users-lounge/docs/faq.html
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly