Link to home
Start Free TrialLog in
Avatar of bingley
bingley

asked on

datatypes of columns fields in a table

hi, i'm interested in displaying the datatypes of column in  database. right now i'm able to display the columns for a table in a database. now i'm interested in displaying both the datatype and the name of column. any assistance will be appreciated.

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;


public class msaccess3
{
public static void main(String[] args)
{
int i;
Connection conn=null;
//register jdbc driver
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                          conn=DriverManager.getConnection("jdbc:odbc:my_database","dba","sql");
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getColumns(null,null,"login",null);
System.out.println("the columns in the table are:");
while(rs.next()){
String column = rs.getString(4);
System.out.println(column);
}
conn.close();                              
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
             
}
}
}
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial