DatabaseMetaData肯定可以,java doc中有详细
介绍,自己看一下,不断的测试,肯定可以的。

解决方案 »

  1.   

    agree with yipsilon(J3EE研究者), should be ResultSetMetaData,for example (http://groups.google.com/groups?q=ResultSetMetaData+java+example&hl=en&lr=&ie=UTF8&oe=UTF8&selm=000006ed.069efd8d%40usw-ex0108-190.remarq.com&rnum=8)static void dumpResultSet (ResultSet cursor) throws SQLException
        {
            ResultSetMetaData cursorDesc = cursor.getMetaData();
            int colCount = cursorDesc.getColumnCount();
            String [][] tagPairs = getTags (cursorDesc);        while (cursor.next ()) {
                System.out.println ("<Row>");
                for (int i = 0; i < colCount; ++i) {
                    System.out.print ("    "); // indent is really optional
                    System.out.print (tagPairs [i] [0]);
                    String value = cursor.getString (i + 1);
    // should really translate (& => &amp;) and (< => &lt;)
                    System.out.print (value);
                    System.out.println (tagPairs [i] [1]);
                }
                System.out.println ("</Row>");
            }
        }    static String [][] getTags (
            ResultSetMetaData cursorDesc)
        throws SQLException
        {
            int colCount = cursorDesc.getColumnCount();
            String [][] result = new String [colCount][];
            for (int i = 0; i < colCount; ++i) {
                String [] tagPair = new String [2];
                // warning: not every col label is a valid XML identifier
                String colName = cursorDesc.getColumnName(i + 1);
                if (true) {
                    // similar to Oracle's XSQL: <COLNAME>
                    tagPair [0] = "<" + colName + ">";
                    tagPair [1] = "</" + colName + ">";
                }
                else {
                    // choose this one if you want a stable DTD: <Value
    name="COLNAME">
                    tagPair [0] = "<Value name=\"" + colName + "\">";
                    tagPair [1] = "</Value>";
                }
                result [i] = tagPair;
            }
            return result;
        }