Solved

datatypes of columns fields in a table

Posted on 2004-03-31
3
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

688 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