Display Data From Student Table Base The SQL Query
ResultSetMetaData points to data above rows and columns of ResultSet. That is it points to Field Names.
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class TableCreate4 implements ActionListener
{
Statement s;
Frame f;
TextField tf1;
TextArea ta;
ResultSet rs;
ResultSetMetaData rsm;
int count;
TableCreate4()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("Jdbc:Odbc:Maya");
s = c.createStatement();
f = new Frame();
tf1 = new TextField(30);
ta = new TextArea(10,30);
f.setLayout(new FlowLayout());
f.add(tf1);
f.add(ta);
tf1.addActionListener(this);
f.setSize(300,300);
f.setVisible(true);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{
try
{
rs = s.executeQuery(tf1.getText());
rsm = rs.getMetaData();
count = rsm.getColumnCount();
while(rs.next())
{
for(int i=1;i<=count;i++)
{
ta.append(rs.getString(i)+"\t");
}
ta.append("\n");
}
}
catch(Exception ce1)
{
ce1.printStackTrace();
}
f.repaint();
f.validate();
}
public static void main(String[] args)
{
TableCreate4 x = new TableCreate4();
}
}