Giter Site home page Giter Site logo

示例代码报错 about dbmetadata HOT 8 OPEN

abel533 avatar abel533 commented on June 7, 2024
示例代码报错

from dbmetadata.

Comments (8)

abel533 avatar abel533 commented on June 7, 2024

你用的什么数据库?

from dbmetadata.

kictto avatar kictto commented on June 7, 2024

mysql

from dbmetadata.

abel533 avatar abel533 commented on June 7, 2024

版本呢?

from dbmetadata.

kictto avatar kictto commented on June 7, 2024

5.7.16

from dbmetadata.

abel533 avatar abel533 commented on June 7, 2024

我用DBS1.0的程序连接数据库试了试没问题,你是通过代码调用遇到的错误?

from dbmetadata.

kictto avatar kictto commented on June 7, 2024

刚开始做测试的时候,直接参考你给的示例
我的代码:

InputStream in = CodeGenerator.class.getClassLoader().getResourceAsStream("jdbc.properties");
        Properties properties = new Properties();
        try {
            properties.load(in);
        } catch (IOException e) {
            throw new RuntimeException("资源文件读取错误,配置文件的位置不正确");
        }
        SimpleDataSource simpleDataSource = new SimpleDataSource(Dialect.MYSQL,
                properties.getProperty("jdbc.url"),
                properties.getProperty("jdbc.username"),
                properties.getProperty("jdbc.password"));
        DBMetadataUtils dbMetadataUtils = new DBMetadataUtils(simpleDataSource);
        String catalog = simpleDataSource.getConnection().getCatalog();
        DatabaseConfig config = new DatabaseConfig(catalog, "%");
        List<IntrospectedTable> list = dbMetadataUtils.introspectTables(config);

        for (IntrospectedTable table : list) {
            System.out.println(table.getName() + ":");

            for (IntrospectedColumn column : table.getAllColumns()) {
                System.out.println(column.getName() + " - " +
                        column.getDefaultValue() + " - " +
                        column.getJdbcTypeName() + " - " +
                        column.getJavaProperty() + " - " +
                        column.getFullyQualifiedJavaType().getFullyQualifiedName() + " - " +
                        column.getRemarks());
                //System.out.println(column.toString());
            }
        }

异常:

Exception in thread "main" java.sql.SQLException: Column name pattern can not be NULL or empty.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:505)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:479)
	at com.mysql.cj.jdbc.DatabaseMetaData.getColumns(DatabaseMetaData.java:2074)
	at com.github.abel533.database.introspector.DatabaseIntrospector.getColumns(DatabaseIntrospector.java:327)
	at com.github.abel533.database.introspector.DatabaseIntrospector.introspectTables(DatabaseIntrospector.java:259)
	at com.github.abel533.utils.DBMetadataUtils.introspectTables(DBMetadataUtils.java:128)

问题定位到:

protected Map<IntrospectedTable, List<IntrospectedColumn>> getColumns(DatabaseConfig config) throws SQLException {
        Map<IntrospectedTable, List<IntrospectedColumn>> answer = new HashMap<IntrospectedTable, List<IntrospectedColumn>>();

        ResultSet rs = dbMetadataUtils.getDatabaseMetaData().getColumns(
                config.getCatalog(),
                config.getSchemaPattern(),
                config.getTableNamePattern(),
                null);

将getColumns的第四个参数null,改成"%",就可以正常运行了

from dbmetadata.

abel533 avatar abel533 commented on June 7, 2024

我找时间试试。

from dbmetadata.

kictto avatar kictto commented on June 7, 2024

OK,我就先改成%用了

from dbmetadata.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.