Write a program to display information about all columns in the student table. (UseResultSetMetaData).
import java.sql.*;
import java.io.*;
class Ass2seta3
{
public static void main(String args[])
{
Connection c=null;
Statement stmt=null;
ResultSet rs=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");
stmt=c.createStatement();
rs=stmt.executeQuery("Select * from Student");
ResultSetMetaData rsmd=rs.getMetaData();
int cc=rsmd.getColumnCount();
System.out.println("TOTAL NUMBER OF COLUMNS :"+cc);
for(int i=1;i<=cc;i++)
{
System.out.println("COLUMN NUMBER: "+ i);
System.out.println("COLUMN NAME: "+ rsmd.getColumnName(i));
System.out.println("COLUMN TYPE: "+ rsmd.getColumnTypeName(i));
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
0 Comments
If anyone has Doubts or suggestions please let me know