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.od bc.JdbcOdb cDriver");
conn=DriverManager.getConn ection("jd bc:odbc:my _database" ,"dba","sq l");
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getColumns(null,null, "login",nu ll);
System.out.println("the columns in the table are:");
while(rs.next()){
String column = rs.getString(4);
System.out.println(column) ;
}
conn.close();
}
catch(ClassNotFoundExcepti on e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
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.od
conn=DriverManager.getConn
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getColumns(null,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(ClassNotFoundExcepti
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.