Re: jdbc metadata -- auto increment information bug

Ronald Klop <[email protected]>
Newsgroups gmane.comp.db.mysql.java
Message-ID <12176720.26901156767605270.JavaMail.tomcat@localhost>
You can find the info in ResultSetMetaData. I use something like this.




    private Set<String> getAutoIncrementColumns(Connection conn, String tblName)
            throws SQLException {
        Statement s = conn.createStatement(
                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet rs = s.executeQuery(
                "SELECT * FROM " + tblName + " WHERE 1 = 0");
        ResultSetMetaData meta = rs.getMetaData();
        int columnCount = meta.getColumnCount();
        Set<String> results = new HashSet<String>();
        for (int i = 1; i <= columnCount; i++) {
            if (meta.isAutoIncrement(i)) {
                String colName = meta.getColumnName(i);
                results.add(colName);
            }
        }
        return results;
    }



On Sun Aug 27 21:45:15 CEST 2006 "j.random.programmer" <[email protected]> wrote:
> Hi:
> 
> The JDBC DaatabaseMetaData class has a getColumns()
> method. This 
> returns meta data about a column. This is useful when
> using a O/R tool 
> to generate java classes that encapsulate table/column
> info.
> 
> So here is the problem. We need to know if a column is
> auto-increment.
> 
> Previous drivers returned this info via the "REMARKS"
> field in the
> getColumns() method. However, the drivers do not
> return ANY information at all in the remarks field for
> auto-increment columns
> (it is empty), so now there is no way to know if a
> column is auto increment or not.
> 
> I've tried this with both the latest 3.x and 5.x
> drivers and have the
> same problem. I am running this against a 5.0.24
> database.
> 
> Best regards,
> --j
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> -- 
> MySQL Java Mailing List
> For list archives: http://lists.mysql.com/java
> To unsubscribe: http://lists.mysql.com/[email protected]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.