Comments (8)
你用的什么数据库?
from dbmetadata.
mysql
from dbmetadata.
版本呢?
from dbmetadata.
5.7.16
from dbmetadata.
我用DBS1.0的程序连接数据库试了试没问题,你是通过代码调用遇到的错误?
from dbmetadata.
刚开始做测试的时候,直接参考你给的示例
我的代码:
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.
我找时间试试。
from dbmetadata.
OK,我就先改成%用了
from dbmetadata.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbmetadata.