Solved

datatypes of columns fields in a table

Posted on 2004-03-31
3
186 Views
Last Modified: 2010-03-31
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();
             
}
}
}
0
Comment
Question by:bingley
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 20 total points
ID: 10724037
Try something like:


// Map

types.put(new Integer(Types.SMALLINT), "SMALLINT");


ResultSetMetaData rsmd = rs.getMetaData();
String type = (String)types.get(rsmd.getColumnType(1));
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question