Solved

datatypes of columns fields in a table

Posted on 2004-03-31
3
178 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JList custom Cell Renderer refresh 15 56
hibernate insert example 13 28
arguments to jar 5 26
String array comparison 4 32
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now