Skip to content

Commit

Permalink
增加sql server支持
Browse files Browse the repository at this point in the history
  • Loading branch information
zouzg committed May 2, 2017
1 parent 496df5b commit 0ade97a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/zzg/mybatis/generator/util/DbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public static List<String> getTableNames(DatabaseConfig config) throws Exception
_LOG.info("getTableNames, connection url: {}", url);
Connection conn = DriverManager.getConnection(url, config.getUsername(), config.getPassword());
DatabaseMetaData md = conn.getMetaData();
ResultSet rs = md.getTables(null, config.getUsername().toUpperCase(), null, null);
ResultSet rs;
if (DbType.valueOf(config.getDbType()) == DbType.SQL_Server) {
rs = md.getTables(config.getSchema(), null, null, null);
} else {
rs = md.getTables(null, config.getUsername().toUpperCase(), null, new String[] {"TABLE"});
}
List<String> tables = new ArrayList<>();
while (rs.next()) {
tables.add(rs.getString(3));
Expand Down
Binary file added src/main/resources/lib/sqljdbc4-4.0.jar
Binary file not shown.

0 comments on commit 0ade97a

Please sign in to comment.