From 0d6aec3f2b87dc681e268eb17fbc1c96370d0cf7 Mon Sep 17 00:00:00 2001 From: Owen Zou Date: Sat, 21 Jan 2017 22:52:50 +0800 Subject: [PATCH] =?UTF-8?q?fix=20Oracle=E8=BF=9E=E6=8E=A5=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 + pom.xml | 2 - .../controller/NewConnectionController.java | 180 +++++++++--------- .../zzg/mybatis/generator/util/DbUtil.java | 2 +- src/main/resources/fxml/MainUI.fxml | 4 +- 5 files changed, 99 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 4355c74f..fb077d51 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,12 @@ mybatis-generator-gui是基于[mybatis generator](http://www.mybatis.org/generat Eclipse or IntelliJ IDEA中启动, 找到MainUI类并运行就可以了 +#### Oracle用户请注意 +由于Oracle的驱动在maven官方的repository中没有,Oracle的用户需要手动安装一下驱动,cd到项目目录下,执行: + + mvn install:install-file -Dfile=./src/main/resources/connector/ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.3.0 -Dpackaging=jar -DgeneratePom=true + + ### 文档 更多详细文档请参考本库的Wiki * [Usage](https://github.com/astarring/mybatis-generator-gui/wiki/Usage-Guide) diff --git a/pom.xml b/pom.xml index c7d5553c..3672cdcc 100644 --- a/pom.xml +++ b/pom.xml @@ -55,8 +55,6 @@ com.oracle ojdbc14 10.2.0.3.0 - system - ${project.basedir}/src/main/resources/connector/ojdbc14.jar org.postgresql diff --git a/src/main/java/com/zzg/mybatis/generator/controller/NewConnectionController.java b/src/main/java/com/zzg/mybatis/generator/controller/NewConnectionController.java index cb476ae3..846d1e28 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/NewConnectionController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/NewConnectionController.java @@ -11,108 +11,108 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.net.MalformedURLException; import java.net.URL; import java.util.ResourceBundle; public class NewConnectionController extends BaseFXController { - private static final Logger _LOG = LoggerFactory.getLogger(NewConnectionController.class); + private static final Logger _LOG = LoggerFactory.getLogger(NewConnectionController.class); - @FXML - private TextField nameField; - @FXML - private TextField hostField; - @FXML - private TextField portField; - @FXML - private TextField userNameField; - @FXML - private TextField passwordField; -// @FXML -// private CheckBox savePwdCheckBox; - @FXML - private TextField schemaField; - @FXML - private ChoiceBox encodingChoice; - @FXML - private ChoiceBox dbTypeChoice; - private MainUIController mainUIController; + @FXML + private TextField nameField; + @FXML + private TextField hostField; + @FXML + private TextField portField; + @FXML + private TextField userNameField; + @FXML + private TextField passwordField; + @FXML + private TextField schemaField; + @FXML + private ChoiceBox encodingChoice; + @FXML + private ChoiceBox dbTypeChoice; + private MainUIController mainUIController; - @Override - public void initialize(URL location, ResourceBundle resources) { - } + @Override + public void initialize(URL location, ResourceBundle resources) { + } - @FXML - void saveConnection() { - String name = nameField.getText(); - String host = hostField.getText(); - String port = portField.getText(); - String userName = userNameField.getText(); - String password = passwordField.getText(); - String encoding = encodingChoice.getValue(); - String dbType = dbTypeChoice.getValue(); + @FXML + void saveConnection() { + String name = nameField.getText(); + String host = hostField.getText(); + String port = portField.getText(); + String userName = userNameField.getText(); + String password = passwordField.getText(); + String encoding = encodingChoice.getValue(); + String dbType = dbTypeChoice.getValue(); - DatabaseConfig dbConfig = new DatabaseConfig(); - dbConfig.setHost(host); - dbConfig.setPort(port); - dbConfig.setDbType(dbType); - dbConfig.setUsername(userName); - dbConfig.setPassword(password); -// if (savePwdCheckBox.isSelected()) { -// } - dbConfig.setSchema(schemaField.getText()); - dbConfig.setEncoding(encoding); - try { - ConfigHelper.saveDatabaseConfig(name, dbConfig); - getDialogStage().close(); - mainUIController.loadLeftDBTree(); - } catch (Exception e) { - _LOG.error(e.getMessage(), e); - AlertUtil.showErrorAlert(e.getMessage()); - } - } + DatabaseConfig dbConfig = new DatabaseConfig(); + dbConfig.setHost(host); + dbConfig.setPort(port); + dbConfig.setDbType(dbType); + dbConfig.setUsername(userName); + dbConfig.setPassword(password); + dbConfig.setSchema(schemaField.getText()); + dbConfig.setEncoding(encoding); + try { + ConfigHelper.saveDatabaseConfig(name, dbConfig); + getDialogStage().close(); + mainUIController.loadLeftDBTree(); + } catch (Exception e) { + _LOG.error(e.getMessage(), e); + AlertUtil.showErrorAlert(e.getMessage()); + } + } - @FXML - void testConnection() { - String name = nameField.getText(); - String host = hostField.getText(); - String port = portField.getText(); - String userName = userNameField.getText(); - String password = passwordField.getText(); - String encoding = encodingChoice.getValue(); - String dbType = dbTypeChoice.getValue(); - DatabaseConfig config = new DatabaseConfig(); - config.setName(name); - config.setDbType(dbType); - config.setHost(host); - config.setPort(port); - config.setUsername(userName); - config.setPassword(password); - config.setSchema(schemaField.getText()); - config.setEncoding(encoding); - String url = DbUtil.getConnectionUrlWithSchema(config); - System.out.println(url); - try { - DbUtil.getConnection(config); - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setContentText("Connection success"); - alert.show(); - } catch (Exception e) { - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setContentText("Connection failed"); - alert.show(); - } + @FXML + void testConnection() { + String name = nameField.getText(); + String host = hostField.getText(); + String port = portField.getText(); + String userName = userNameField.getText(); + String password = passwordField.getText(); + String encoding = encodingChoice.getValue(); + String dbType = dbTypeChoice.getValue(); + DatabaseConfig config = new DatabaseConfig(); + config.setName(name); + config.setDbType(dbType); + config.setHost(host); + config.setPort(port); + config.setUsername(userName); + config.setPassword(password); + config.setSchema(schemaField.getText()); + config.setEncoding(encoding); - } + String url = DbUtil.getConnectionUrlWithSchema(config); + System.out.println(url); + try { + DbUtil.getConnection(config); + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setContentText("Connection success"); + alert.show(); + } catch (Exception e) { + _LOG.error(e.getMessage(), e); + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setContentText("Connection failed"); + alert.show(); + } - @FXML - void cancel() { - getDialogStage().close(); - } - - void setMainUIController(MainUIController controller) { - this.mainUIController = controller; - } + } + + @FXML + void cancel() { + getDialogStage().close(); + } + + void setMainUIController(MainUIController controller) { + this.mainUIController = controller; + } } diff --git a/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java b/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java index 310cc5ee..a2c3bc64 100644 --- a/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java +++ b/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java @@ -35,7 +35,7 @@ public static List getTableNames(DatabaseConfig config) throws Exception DriverManager.setLoginTimeout(DB_CONNECTION_TIMEOUTS_SECONDS); Connection conn = DriverManager.getConnection(url, config.getUsername(), config.getPassword()); DatabaseMetaData md = conn.getMetaData(); - ResultSet rs = md.getTables(null, null, null, null); + ResultSet rs = md.getTables(null, config.getUsername().toUpperCase(), null, null); List tables = new ArrayList<>(); while (rs.next()) { tables.add(rs.getString(3)); diff --git a/src/main/resources/fxml/MainUI.fxml b/src/main/resources/fxml/MainUI.fxml index e1af41c5..b476a6c0 100644 --- a/src/main/resources/fxml/MainUI.fxml +++ b/src/main/resources/fxml/MainUI.fxml @@ -49,12 +49,12 @@
- + - +