Skip to content

Commit 647ef2a

Browse files
author
msuno
committed
增加主机端口连接
1 parent 5daa287 commit 647ef2a

21 files changed

+184
-181
lines changed

TableStructure.iml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9+
<excludeFolder url="file://$MODULE_DIR$/target" />
10+
</content>
11+
<orderEntry type="inheritedJdk" />
12+
<orderEntry type="sourceFolder" forTests="false" />
13+
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15+
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.37" level="project" />
16+
<orderEntry type="library" name="Maven: com.oracle:ojdbc6:11.2.0.3" level="project" />
17+
<orderEntry type="library" name="Maven: com.deepoove:poi-tl:1.3.1" level="project" />
18+
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.7" level="project" />
19+
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.3.2" level="project" />
20+
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:3.16" level="project" />
21+
<orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.04" level="project" />
22+
<orderEntry type="library" name="Maven: org.apache.poi:poi:3.16" level="project" />
23+
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
24+
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.1" level="project" />
25+
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:3.16" level="project" />
26+
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:2.6.0" level="project" />
27+
<orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" />
28+
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.5" level="project" />
29+
<orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />
30+
</component>
31+
<component name="sonarModuleSettings">
32+
<option name="alternativeWorkingDirPath" value="" />
33+
<option name="localAnalysisScripName" value="&lt;PROJECT&gt;" />
34+
<option name="serverName" value="&lt;PROJECT&gt;" />
35+
<option name="useAlternativeWorkingDir" value="false" />
36+
<option name="workingDirSelection" value="&lt;MODULE&gt;" />
37+
</component>
38+
</module>

pom.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>com.msw</groupId>
6-
<artifactId>TableStructure</artifactId>
6+
<artifactId>export-database-structure</artifactId>
77
<version>0.0.1-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

10-
<name>TableStructure</name>
10+
<name>export-database-structure</name>
1111
<url>http://maven.apache.org</url>
1212

1313
<properties>
@@ -42,14 +42,12 @@
4242
<groupId>org.slf4j</groupId>
4343
<artifactId>slf4j-log4j12</artifactId>
4444
<version>1.7.5</version>
45-
<scope>provided</scope>
46-
</dependency>
45+
</dependency>
4746
<dependency>
4847
<groupId>log4j</groupId>
4948
<artifactId>log4j</artifactId>
5049
<version>1.2.14</version>
51-
<scope>provided</scope>
52-
</dependency>
50+
</dependency>
5351

5452
</dependencies>
5553
<build>

src/main/java/com/msw/java/App.java

Lines changed: 35 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.FileNotFoundException;
44
import java.io.FileOutputStream;
55
import java.io.IOException;
6+
import java.sql.Connection;
67
import java.sql.ResultSet;
78
import java.sql.SQLException;
89
import java.util.ArrayList;
@@ -31,7 +32,7 @@ public static void main( String[] args ) throws IOException
3132

3233

3334
//使用jar的命令,参数有4个,如果没有4个直接退出,没得商量
34-
if(args.length<4){
35+
if(args.length<6){
3536
log.info("参数:");
3637
log.info("-n=数据库名称");
3738
log.info("-u=用户名");
@@ -57,89 +58,44 @@ public static void main( String[] args ) throws IOException
5758
public static void Oracle(Map<String,String> map) throws IOException{
5859
//默认生成的文件名
5960
String outFile = map.get("-d")+"/数据库表结构(ORACLE).docx";
60-
6161
//查询表的名称以及一些表需要的信息
6262
String oracleSql1 = "select ut.table_name as table_name,ut.tablespace_name as engine,ut.buffer_pool as table_collation, uc.table_type as table_type,uc.comments as table_comment,ut.last_analyzed as create_options from user_tables ut,user_tab_comments uc where ut.table_name=uc.table_name";
63-
6463
String oracleSql2 = "select rownum as ordinal_position,c.nullable as is_nullable,c.data_default as column_default,c.data_type as data_type,c.data_length as character_maximum_length,t.column_name as column_name,t.comments as column_comment from user_col_comments t,user_tab_columns c where c.column_name=t.column_name and c.table_name=t.table_name and t.table_name='";
65-
66-
ResultSet rs = OracleUtils.getResultSet(OracleUtils.getConnnection(map.get("-u"), map.get("-p")),oracleSql1);
67-
68-
log.info("开始生成文件");
69-
List<Map<String, String>> list = getTableName(rs);
70-
RowRenderData header = getHeader();
71-
Map<String,Object> datas = new HashMap<String, Object>();
72-
datas.put("title", "数据结构表(ORACLE)");
73-
List<Map<String,Object>> tableList = new ArrayList<Map<String,Object>>();
74-
int i = 0;
75-
for(Map<String, String> str : list){
76-
log.info(str);
77-
i++;
78-
String sql = oracleSql2+str.get("table_name")+"'";
79-
ResultSet set = OracleUtils.getResultSet(OracleUtils.getConnnection(map.get("-u"), map.get("-p")),sql);
80-
List<RowRenderData> rowList = getRowRenderData(set);
81-
Map<String,Object> data = new HashMap<String,Object>();
82-
data.put("no", ""+i);
83-
data.put("table_comment",str.get("table_comment")+"");
84-
data.put("engine",str.get("engine")+"");
85-
data.put("table_collation",str.get("table_collation")+"");
86-
data.put("table_type",str.get("table_type")+"");
87-
data.put("name", new TextRenderData(str.get("table_name"), POITLStyle.getHeaderStyle()));
88-
data.put("table", new MiniTableRenderData(header, rowList));
89-
tableList.add(data);
90-
}
91-
92-
datas.put("tablelist", new DocxRenderData(FileUtils.Base64ToFile(outFile,false), tableList));
93-
XWPFTemplate template = XWPFTemplate.compile(FileUtils.Base64ToInputStream()).render(datas);
94-
95-
FileOutputStream out = null;
96-
try {
97-
out = new FileOutputStream(outFile);
98-
log.info("生成文件结束");
99-
} catch (FileNotFoundException e) {
100-
e.printStackTrace();
101-
log.info("生成文件失败");
102-
}finally {
103-
try {
104-
template.write(out);
105-
out.flush();
106-
out.close();
107-
template.close();
108-
109-
} catch (IOException e) {
110-
e.printStackTrace();
111-
}
112-
}
64+
ResultSet rs = OracleUtils.getResultSet(OracleUtils.getConnnection(String.format("jdbc:oracle:thin:@%s:%s:ORCL",map.get("h"),map.get("p")),map.get("-u"), map.get("-p")),oracleSql1);
65+
Connection con = OracleUtils.getConnnection(String.format("jdbc:oracle:thin:@%s:%s:ORCL",map.get("h"),map.get("p")),map.get("-u"), map.get("-p"));
66+
createDoc(rs,oracleSql2,map,outFile,false,"Oracle数据库表结构",con);
11367
}
11468

11569
public static void MySQL(Map<String,String> map) throws IOException{
11670
//默认生成的文件名
11771
String outFile = map.get("-d")+"/数据库表结构(MySQL).docx";
118-
11972
//查询表的名称以及一些表需要的信息
12073
String mysqlSql1 = "SELECT table_name, table_type , ENGINE,table_collation,table_comment, create_options FROM information_schema.TABLES WHERE table_schema='"+map.get("-n")+"'";
121-
12274
//查询表的结构信息
12375
String mysqlSql2 = "SELECT ordinal_position,column_name,column_type, column_key, extra ,is_nullable, column_default, column_comment,data_type,character_maximum_length "
12476
+ "FROM information_schema.columns WHERE table_schema='"+map.get("-n")+"' and table_name='";
77+
ResultSet rs = SqlUtils.getResultSet(SqlUtils.getConnnection(String.format("jdbc:mysql://%s:%s",map.get("h"),map.get("p")),map.get("-u"), map.get("-p")),mysqlSql1);
78+
Connection con = SqlUtils.getConnnection(String.format("jdbc:mysql://%s:%s",map.get("h"),map.get("p")),map.get("-u"), map.get("-p"));
79+
createDoc(rs,mysqlSql2,map,outFile,true,"MySQL数据库表结构",con);
12580

126-
127-
ResultSet rs = SqlUtils.getResultSet(SqlUtils.getConnnection(map.get("-u"), map.get("-p")),mysqlSql1);
128-
81+
}
82+
83+
84+
private static void createDoc(ResultSet rs,String sqls,Map<String,String> map,String outFile,boolean type,String title,Connection con) throws IOException{
12985
log.info("开始生成文件");
13086
List<Map<String, String>> list = getTableName(rs);
13187
RowRenderData header = getHeader();
132-
Map<String,Object> datas = new HashMap<String, Object>();
133-
datas.put("title", "数据结构表(MySQL)");
88+
Map<String,Object> datas = new HashMap<>();
89+
datas.put("title", title);
13490
List<Map<String,Object>> tableList = new ArrayList<Map<String,Object>>();
13591
int i = 0;
13692
for(Map<String, String> str : list){
13793
log.info(str);
13894
i++;
139-
String sql = mysqlSql2+str.get("table_name")+"'";
140-
ResultSet set = SqlUtils.getResultSet(SqlUtils.getConnnection(map.get("-u"), map.get("-p")),sql);
95+
String sql = sqls+str.get("table_name")+"'";
96+
ResultSet set = SqlUtils.getResultSet(con,sql);
14197
List<RowRenderData> rowList = getRowRenderData(set);
142-
Map<String,Object> data = new HashMap<String,Object>();
98+
Map<String,Object> data = new HashMap<>();
14399
data.put("no", ""+i);
144100
data.put("table_comment",str.get("table_comment")+"");
145101
data.put("engine",str.get("engine")+"");
@@ -149,10 +105,10 @@ public static void MySQL(Map<String,String> map) throws IOException{
149105
data.put("table", new MiniTableRenderData(header, rowList));
150106
tableList.add(data);
151107
}
152-
153-
datas.put("tablelist", new DocxRenderData(FileUtils.Base64ToFile(outFile,true), tableList));
108+
109+
datas.put("tablelist", new DocxRenderData(FileUtils.Base64ToFile(outFile,type), tableList));
154110
XWPFTemplate template = XWPFTemplate.compile(FileUtils.Base64ToInputStream()).render(datas);
155-
111+
156112
FileOutputStream out = null;
157113
try {
158114
out = new FileOutputStream(outFile);
@@ -166,20 +122,18 @@ public static void MySQL(Map<String,String> map) throws IOException{
166122
out.flush();
167123
out.close();
168124
template.close();
169-
125+
170126
} catch (IOException e) {
171127
e.printStackTrace();
172-
}
128+
}
173129
}
174-
}
130+
}
175131

176132
/**
177133
* 检查缺少的参数
178-
* @param args
179-
* @return
180134
*/
181135
private static Map<String, String> Check(String[] args) {
182-
Map<String, String> map = new HashMap<String, String>();
136+
Map<String, String> map = new HashMap<>();
183137
for(String str: args){
184138
String[] split = str.split("=");
185139
map.put(split[0], split[1]);
@@ -201,7 +155,14 @@ private static Map<String, String> Check(String[] args) {
201155
log.info("请输入保存文件的目录!");
202156
System.exit(0);
203157
}
204-
158+
if(!map.containsKey("h")){
159+
log.info("请输入地址!");
160+
System.exit(0);
161+
}
162+
if(!map.containsKey("p")){
163+
log.info("请输入端口");
164+
System.exit(0);
165+
}
205166
return map;
206167
}
207168

@@ -224,11 +185,10 @@ private static RowRenderData getHeader(){
224185

225186
/**
226187
* 获取一张表的结构数据
227-
* @param set
228188
* @return List<RowRenderData>
229189
*/
230190
private static List<RowRenderData> getRowRenderData(ResultSet set) {
231-
List<RowRenderData> result = new ArrayList<RowRenderData>();
191+
List<RowRenderData> result = new ArrayList<>();
232192

233193
try {
234194
int i = 0;
@@ -260,15 +220,14 @@ private static List<RowRenderData> getRowRenderData(ResultSet set) {
260220

261221
/**
262222
* 获取数据库的所有表名及表的信息
263-
* @param rs
264223
* @return list
265224
*/
266225
private static List<Map<String,String>> getTableName(ResultSet rs){
267-
List<Map<String,String>> list = new ArrayList<Map<String,String>>();
226+
List<Map<String,String>> list = new ArrayList<>();
268227

269228
try {
270229
while(rs.next()){
271-
Map<String,String> result = new HashMap<String,String>();
230+
Map<String,String> result = new HashMap<>();
272231
result.put("table_name", rs.getString("table_name")+"");
273232
result.put("table_type", rs.getString("table_type")+"");
274233
result.put("engine", rs.getString("engine")+"");

src/main/java/com/msw/java/Login.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.msw.java;
22

33
import javafx.application.Application;
4+
import javafx.application.Platform;
45
import javafx.fxml.FXMLLoader;
56
import javafx.scene.Parent;
67
import javafx.scene.Scene;
@@ -14,9 +15,23 @@ public void start(Stage primaryStage) throws Exception {
1415
primaryStage.setTitle("工具类");
1516
primaryStage.setScene(new Scene(login));
1617
primaryStage.show();
18+
try {
19+
Thread.sleep(3000);
20+
Platform.runLater(() -> {
21+
try{
22+
new Main().start(new Stage());
23+
}catch (Exception e){
24+
e.printStackTrace();
25+
}
26+
});
27+
primaryStage.hide();
28+
}catch (Exception e){
29+
e.printStackTrace();
30+
}
1731
}
1832

1933
public static void main(String[] args) {
2034
launch(args);
2135
}
36+
2237
}

src/main/java/com/msw/java/LoginController.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,20 @@
33
import java.net.URL;
44
import java.util.ResourceBundle;
55

6-
import javafx.event.ActionEvent;
76
import javafx.fxml.FXML;
87
import javafx.fxml.Initializable;
9-
import javafx.scene.control.Button;
10-
import javafx.scene.control.PasswordField;
11-
import javafx.scene.control.TextField;
128
import javafx.scene.image.Image;
139
import javafx.scene.image.ImageView;
14-
import javafx.stage.Stage;
1510

1611
public class LoginController implements Initializable{
1712

1813
@FXML
1914
private ImageView img;
2015

21-
@FXML
22-
private TextField username;
23-
24-
@FXML
25-
private PasswordField password;
26-
27-
@FXML
28-
private Button reset;
29-
30-
@FXML
31-
private Button login;
32-
3316
@Override
3417
public void initialize(URL location, ResourceBundle resources) {
3518
Image image = new Image("/head_2.jpg");
3619
img.setImage(image);
3720

3821
}
39-
40-
public void reset(ActionEvent event){
41-
username.setText("");
42-
password.setText("");
43-
}
44-
45-
public void login(ActionEvent event){
46-
if(!username.getText().toString().equals("root")
47-
||!password.getText().toString().equals("123456")){
48-
MainController.Alerts(false, "用户名或密码错误!");
49-
return ;
50-
}
51-
MainController.Alerts(true, "登录成功!");
52-
try {
53-
Main main = new Main();
54-
main.start(new Stage());
55-
} catch (Exception e) {
56-
// TODO Auto-generated catch block
57-
e.printStackTrace();
58-
}
59-
Stage stage = (Stage) login.getScene().getWindow();
60-
stage.close();
61-
}
62-
6322
}

0 commit comments

Comments
 (0)