Write a program to display information about the database and list all the tables in the database. (Use DatabaseMetaData).
import java.sql.*;
import java.io.*;
class Ass2seta2
{
public static void main(String args[])
{
Connection c=null;
ResultSet rs=null;
DatabaseMetaData dbmd=null;
try
{
Class.forName("org.postgresql.Driver");
c=DriverManager.getConnection("jdbc:postgresql://192.168.100.10/tybcs8",
"tybcs8","");
if(c==null)
{
System.out.println("Connection not established");
}
else
{
System.out.println("Connection established");
dbmd=c.getMetaData();
System.out.println("DRIVER NAME: "+ dbmd.getDriverName());
System.out.println("PRODUCT NAME: "+ dbmd.getDatabaseProductName());
System.out.println("DRIVER VERSION: "+ dbmd.getDriverVersion());
System.out.println("PRODUCT VERSION: "+ dbmd.getDatabaseProductVersion());
String []t={"TABLE"};
rs=dbmd.getTables(null,null,null,t);
System.out.println("LIST OF TABLES ARE:");
while(rs.next())
{
String tb1=rs.getString("TABLE_NAME");
System.out.println("Table:"+tb1);
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
0 Comments
If anyone has Doubts or suggestions please let me know