In JDBC there is some classes giving table and column name and other info. Example:
<pre>
import java.util.Vector;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TableInfo {
private DBConnection dbc = null;
private String tableName;
private int columns = 0;
private String columnNames[];
private String columnTypes[];
private boolean isView;
private final int TYPE_INT = 0;
private final int TYPE_VARCHAR = 1;
private final int TYPE_TIMESTAMP = 2;
private final int TYPE_DATE = 3;
public TableInfo(DBConnection conn, String name) {
tableName = name;
dbc = conn;
columns = 0;
}
private void getDefinition() throws TableDefinitionException {
try {
getDefinition(tableName.toUpperCase());
} catch (Exception e) {
getDefinition(tableName.toLowerCase());
}
}
private void getDefinition(String tabName) throws TableDefinitionException {
try {
DatabaseMetaData dmd = dbc.getConnection().getMetaData();
ResultSet rs = dmd.getTables(null, "", tabName, null);
if (rs.next()) {
if (rs.getString(4).equals("TABLE"

|| rs.getString(4).equals("VIEW"

) {
isView = rs.getString(4).equals("VIEW"

;
ResultSet rs2 = dmd.getColumns(null, "", rs.getString(3), "%"

;
Vector v = new Vector();
while (rs2.next()) {
v.add(rs2.getString(4));
v.add(rs2.getString(5));
}
columnNames = new String[v.size()/2];
columnTypes = new String[v.size()/2];
for (int i=0; i<v.size()/2; i++) {
columnNames
= (String)v.elementAt(i*2);
columnTypes = (String)v.elementAt(i*2+1);
}
columns = v.size()/2;
}
} else {
throw new TableDefinitionException("Not found " + tabName);
}
} catch (SQLException e) {
throw new TableDefinitionException("Error " + tabName);
}
}
public String getTableName() {
return tableName;
}
public boolean isView() throws TableDefinitionException {
if (columns == 0) {
getDefinition();
}
return isView;
}
public int getColumnCount() throws TableDefinitionException {
if (columns == 0) {
getDefinition();
}
return columns;
}
public String getColumnName(int index) throws TableDefinitionException {
if (columns == 0) {
getDefinition();
}
if (index > 0 && index <= columns) {
return columnNames[index - 1];
} else {
throw new TableDefinitionException("Felaktigt index (" + index + "
(getColumnName)"
;
}
}
public String getColumnType(int index) throws TableDefinitionException {
if (columns == 0) {
getDefinition();
}
if (index > 0 && index <= columns) {
return columnTypes[index - 1];
} else {
throw new TableDefinitionException("Wrong index (" + index + "
(getColumnType)"
;
}
}
}
</pre>