to:bobosji(波波司机) desc area_table 是显示table的结构。 ResultSet rs = stmt.exeQuery("select * from area_talbe");//stmt 是statement对象。 ResultSetMetaData rsmd = rs.getMetaData(); int numCols = rsmd.getColumnCount(); //get the number of columns for ( int i =1;i<=numCols;i++){ if (i>1) System.out.print(","); System.out.print(rsmd.getColumnLabel(i));//显示每个列的标题 } System.out.println(""); }
方法:getColumnName public String getColumnName(int column) throws SQLException**Get the designated column's name.方法:getColumnLabel public String getColumnLabel(int column) throws SQLException**Gets the designated column's suggested title for use in printouts and displays.如果是要显示你的中文列名,用getColumnLabel; 如果要根据列名来取数据,用getColumnName。另:to pang: desc area_table 是哪里的用法?
用ResultSetMetaData类的getColumnCount()
记得要catch SQLException
to bobosji(波波司机) desc命令在oracle和sqlserver都可。是标准的sql文。 后接表名。用来显示表的结构。
以下是我程序中的一个SQL语句,这个SQL语句就是用来读出DbName表的列名和列号了。 SQL_SEL_FIELDS = "SELECT * FROM DBA_TAB_COLUMNS WHERE TABLE_NAME = '" + DbName.toUpperCase() +"' ORDER BY COLUMN_ID";
to pang: 原来如此,我只晓得有describe,不晓得还可以缩写的,还以为是descending呢,呵呵
to panq & bobosji: 不知道sysbase里有没有这种表? 用上面的语句可以读出某一个表的所有列名
getColumnType public int getColumnType(int column) throws SQLException Retrieves the designated column's SQL type. Parameters: column - the first column is 1, the second is 2, ... Returns: SQL type from java.sql.Types Throws: SQLException - if a database access error occurs See Also: Types--------------------------------------------------------------------------------getColumnTypeName public String getColumnTypeName(int column) throws SQLException Retrieves the designated column's database-specific type name. Parameters: column - the first column is 1, the second is 2, ... Returns: type name used by the database. If the column type is a user-defined type, then a fully-qualified type name is returned. Throws: SQLException - if a database access error occurs
desc area_table 是显示table的结构。
ResultSet rs = stmt.exeQuery("select * from area_talbe");//stmt 是statement对象。
ResultSetMetaData rsmd = rs.getMetaData();
int numCols = rsmd.getColumnCount(); //get the number of columns
for ( int i =1;i<=numCols;i++){
if (i>1) System.out.print(",");
System.out.print(rsmd.getColumnLabel(i));//显示每个列的标题
}
System.out.println(""); }
public String getColumnName(int column) throws SQLException**Get the designated column's name.方法:getColumnLabel
public String getColumnLabel(int column) throws SQLException**Gets the designated column's suggested title for use in printouts and displays.如果是要显示你的中文列名,用getColumnLabel;
如果要根据列名来取数据,用getColumnName。另:to pang:
desc area_table 是哪里的用法?
desc命令在oracle和sqlserver都可。是标准的sql文。
后接表名。用来显示表的结构。
其他的数据库,我就不知道了!
SQL_SEL_FIELDS = "SELECT * FROM DBA_TAB_COLUMNS WHERE TABLE_NAME = '" + DbName.toUpperCase() +"' ORDER BY COLUMN_ID";
原来如此,我只晓得有describe,不晓得还可以缩写的,还以为是descending呢,呵呵
不知道sysbase里有没有这种表?
用上面的语句可以读出某一个表的所有列名
public int getColumnType(int column)
throws SQLException
Retrieves the designated column's SQL type.
Parameters:
column - the first column is 1, the second is 2, ...
Returns:
SQL type from java.sql.Types
Throws:
SQLException - if a database access error occurs
See Also:
Types--------------------------------------------------------------------------------getColumnTypeName
public String getColumnTypeName(int column)
throws SQLException
Retrieves the designated column's database-specific type name.
Parameters:
column - the first column is 1, the second is 2, ...
Returns:
type name used by the database. If the column type is a user-defined type, then a fully-qualified type name is returned.
Throws:
SQLException - if a database access error occurs