java.sql.SQLException: Parameter metadata not available for the given statement

来源:互联网 发布:程序员试用期总结 编辑:程序博客网 时间:2024/06/10 00:16
static void readMeta(String sql, Object[] params) throws SQLException {        Connection conn = null;        PreparedStatement ps = null;        ResultSet rs = null;        try {            conn = DBConnectionManager.getConnection();            ps = conn.prepareStatement(sql);            ParameterMetaData pmd=ps.getParameterMetaData();            int count=pmd.getParameterCount();            for(int i=1;i<=count;i++){                System.out.print(pmd.getParameterClassName(i)+"  ");                System.out.print(pmd.getParameterMode(i)+"  ");                System.out.print(pmd.getParameterType(i)+"  ");                System.out.println(pmd.getParameterTypeName(i));            }        } finally {            DBConnectionManager.free(rs, ps, conn);        }    }

获取元数据时出错:java.sql.SQLException: Parameter metadata not available for the given statement
将登陆数据库时的链接更改一下就可以了,原来

private static final String DB_URL = "jdbc:mysql://localhost:3306/test";

改为

private static final String DB_URL = "jdbc:mysql://localhost:3306/test?generateSimpleParameterMetadata=true";
0 0
原创粉丝点击