Skip to content

Commit

Permalink
fix Oracle连接失败的issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zouzg committed Jan 21, 2017
1 parent 2663eff commit 0d6aec3
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 95 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/connector/ojdbc14.jar</systemPath>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> encodingChoice;
@FXML
private ChoiceBox<String> 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<String> encodingChoice;
@FXML
private ChoiceBox<String> 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;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/zzg/mybatis/generator/util/DbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static List<String> 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<String> tables = new ArrayList<>();
while (rs.next()) {
tables.add(rs.getString(3));
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fxml/MainUI.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
<center>
<SplitPane dividerPositions="0.15">
<items>
<AnchorPane maxWidth="250.0" minWidth="100.0" prefHeight="618.0" prefWidth="175.0">
<AnchorPane maxWidth="500.0" minWidth="100.0" prefHeight="618.0" prefWidth="200.0">
<children>
<TreeView fx:id="leftDBTree" layoutX="-14.0" maxWidth="0.0" prefHeight="545.0" prefWidth="126.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane>
<AnchorPane minWidth="400.0">
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
Expand Down

0 comments on commit 0d6aec3

Please sign in to comment.