Browse Source

提交 注意mysql-connector-java版本

wanghc 2 years ago
commit
d5ce8e5512

+ 3 - 0
README.md

@@ -0,0 +1,3 @@
+# MysqlTableStructure
+导出mysql,oracle表结构到word文档
+

+ 92 - 0
pom.xml

@@ -0,0 +1,92 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>com.msw</groupId>
+  <artifactId>export-database-structure</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>export-database-structure</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <encoding>UTF-8</encoding>
+    <java.version>1.8</java.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>mysql</groupId>
+      <artifactId>mysql-connector-java</artifactId>
+      <version>8.0.28</version>
+    </dependency>
+    <dependency>
+      <groupId>com.oracle</groupId>
+      <artifactId>ojdbc6</artifactId>
+      <version>11.2.0.3</version>
+    </dependency>
+    <dependency>
+      <groupId>com.deepoove</groupId>
+      <artifactId>poi-tl</artifactId>
+      <version>1.3.1</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <!-- 配置资源文件 -->
+    <resources>
+      <resource>
+        <directory>src/main/java</directory>
+        <includes>
+          <include>**/*.fxml</include>
+          <include>**/*.properties</include>
+          <include>**/*.jpg</include>
+        </includes>
+      </resource>
+    </resources>
+    <!-- 编译插件 -->
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.7.0</version>
+        <configuration>
+          <source>1.8</source>
+          <target>1.8</target>
+          <encoding>UTF-8</encoding>
+        </configuration>
+      </plugin>
+      <!-- 打包成jar包,将依赖一起打包 -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <version>2.6</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>single</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <archive>
+            <manifest>
+              <mainClass>com.msw.java.Main</mainClass>
+            </manifest>
+          </archive>
+          <descriptorRefs>
+            <descriptorRef>jar-with-dependencies</descriptorRef>
+          </descriptorRefs>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

+ 245 - 0
src/main/java/com/msw/java/App.java

@@ -0,0 +1,245 @@
+package com.msw.java;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.data.DocxRenderData;
+import com.deepoove.poi.data.MiniTableRenderData;
+import com.deepoove.poi.data.RowRenderData;
+import com.deepoove.poi.data.TextRenderData;
+
+/**
+ * 把数据库中的表结构导出word中
+ * @author MOSHUNWEI
+ * @version 1.0
+ */
+public class App
+{
+    public static void main( String[] args ) throws IOException
+    {
+    	
+    	
+    	//使用jar的命令,参数有4个,如果没有4个直接退出,没得商量
+    	if(args.length<6){
+    		System.out.println("参数:");
+    		System.out.println("-n=数据库名称");
+    		System.out.println("-u=用户名");
+    		System.out.println("-p=密码");
+    		System.out.println("-d=文件输出路径");
+            System.out.println("h=数据库地址");
+            System.out.println("p=数据库端口");
+    		System.out.println("-t=mysql or oracle defalut mysql");
+    		System.exit(0);
+    	}
+    	
+    	Map<String, String> map = Check(args);
+    	
+    	if(map.get("-t")==null||map.get("-t").equals("mysql")){
+    		MySQL(map);
+    	}else if(map.get("-t").equals("oracle")){
+    		Oracle(map);
+    	}else{
+    		System.out.println("-t=mysql or oracle defalut mysql");
+    		System.exit(0);
+    	}
+		
+    }
+    
+    public static void Oracle(Map<String,String> map) throws IOException{
+    	//默认生成的文件名
+    	String outFile = map.get("-d")+"/数据库表结构(ORACLE).docx";
+    	//查询表的名称以及一些表需要的信息
+    	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";
+    	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='";
+		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);
+		Connection con = OracleUtils.getConnnection(String.format("jdbc:oracle:thin:@%s:%s:ORCL",map.get("h"),map.get("p")),map.get("-u"), map.get("-p"));
+		createDoc(rs,oracleSql2,map,outFile,false,"Oracle数据库表结构",con);
+    }
+    
+    public static void MySQL(Map<String,String> map) throws IOException{
+    	//默认生成的文件名
+    	String outFile = map.get("-d")+"/数据库表结构(MySQL).docx";
+    	//查询表的名称以及一些表需要的信息
+    	String mysqlSql1 = "SELECT table_name, table_type , ENGINE,table_collation,table_comment, create_options FROM information_schema.TABLES WHERE table_schema='"+map.get("-n")+"'";
+    	//查询表的结构信息
+    	String mysqlSql2 = "SELECT ordinal_position,column_name,column_type, column_key, extra ,is_nullable, column_default, column_comment,data_type,character_maximum_length "
+    			+ "FROM information_schema.columns WHERE table_schema='"+map.get("-n")+"' and table_name='";
+		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);
+		Connection con = SqlUtils.getConnnection(String.format("jdbc:mysql://%s:%s",map.get("h"),map.get("p")),map.get("-u"), map.get("-p"));
+		createDoc(rs,mysqlSql2,map,outFile,true,"MySQL数据库表结构",con);
+		
+    }
+    
+    
+    private static void createDoc(ResultSet rs,String sqls,Map<String,String> map,String outFile,boolean type,String title,Connection con) throws IOException{
+		System.out.println("开始生成文件");
+		List<Map<String, String>> list = getTableName(rs);
+		RowRenderData header = getHeader();
+		Map<String,Object> datas = new HashMap<>();
+		datas.put("title", title);
+		List<Map<String,Object>> tableList = new ArrayList<Map<String,Object>>();
+		int i = 0;
+		for(Map<String, String> str : list){
+			System.out.println(str);
+			i++;
+			String sql = sqls+str.get("table_name")+"'";
+			ResultSet set = SqlUtils.getResultSet(con,sql);
+			List<RowRenderData> rowList = getRowRenderData(set);
+			Map<String,Object> data = new HashMap<>();
+			data.put("no", ""+i);
+			data.put("table_comment",str.get("table_comment")+"");
+			data.put("engine",str.get("engine")+"");
+			data.put("table_collation",str.get("table_collation")+"");
+			data.put("table_type",str.get("table_type")+"");
+			data.put("name", new TextRenderData(str.get("table_name"), POITLStyle.getHeaderStyle()));
+			data.put("table", new MiniTableRenderData(header, rowList));
+			tableList.add(data);
+		}
+	
+		datas.put("tablelist", new DocxRenderData(FileUtils.Base64ToFile(outFile,type), tableList));
+		XWPFTemplate template = XWPFTemplate.compile(FileUtils.Base64ToInputStream()).render(datas);
+	
+		FileOutputStream out = null;
+		try {
+			out = new FileOutputStream(outFile);
+			System.out.println("生成文件结束");
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+			System.out.println("生成文件失败");
+		}finally {
+			try {
+				template.write(out);
+				out.flush();
+				out.close();
+				template.close();
+			
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+    
+    /**
+     * 检查缺少的参数
+     */
+    private static Map<String, String> Check(String[] args) {
+    	Map<String, String> map = new HashMap<>();
+    	for(String str: args){
+    		String[] split = str.split("=");
+    		map.put(split[0], split[1]);
+    	}
+    	
+    	if(!map.containsKey("-n")){
+    		System.out.println("请输入数据库名称!");
+    		System.exit(0);
+    	}
+    	if(!map.containsKey("-u")){
+    		System.out.println("请输入数据库用户名!");
+    		System.exit(0);
+    	}
+    	if(!map.containsKey("-p")){
+    		System.out.println("请输入数据库密码!");
+    		System.exit(0);
+    	}
+    	if(!map.containsKey("-d")){
+    		System.out.println("请输入保存文件的目录!");
+    		System.exit(0);
+    	}
+		if(!map.containsKey("h")){
+			System.out.println("请输入地址!");
+			System.exit(0);
+		}
+		if(!map.containsKey("p")){
+			System.out.println("请输入端口");
+			System.exit(0);
+		}
+    	return map;
+	}
+
+	/**
+     * table的表头
+     * @return RowRenderData
+     */
+    private static RowRenderData getHeader(){
+    	RowRenderData header = RowRenderData.build(
+				new TextRenderData("序号", POITLStyle.getHeaderStyle()),
+				new TextRenderData("字段名称", POITLStyle.getHeaderStyle()),
+				new TextRenderData("字段描述", POITLStyle.getHeaderStyle()),
+				new TextRenderData("字段类型", POITLStyle.getHeaderStyle()),
+				new TextRenderData("长度", POITLStyle.getHeaderStyle()),
+				new TextRenderData("允许空", POITLStyle.getHeaderStyle()),
+				new TextRenderData("缺省值", POITLStyle.getHeaderStyle()));
+		header.setStyle(POITLStyle.getHeaderTableStyle());
+		return header;
+    }
+    
+    /**
+     * 获取一张表的结构数据
+     * @return List<RowRenderData>
+     */
+    private static List<RowRenderData> getRowRenderData(ResultSet set) {
+    	List<RowRenderData> result = new ArrayList<>();
+    	
+    	try {
+    		int i = 0;
+			while(set.next()){
+				i++;
+				RowRenderData row = RowRenderData.build(
+						new TextRenderData(set.getString("ordinal_position")+""),
+						new TextRenderData(set.getString("column_name")+""),
+						new TextRenderData(set.getString("column_comment")+""),
+						new TextRenderData(set.getString("data_type")+""),
+						new TextRenderData(set.getString("character_maximum_length")+""),
+						new TextRenderData(set.getString("is_nullable")+""),
+						new TextRenderData(set.getString("column_default")+"")
+						);
+				if(i%2==0){
+					row.setStyle(POITLStyle.getBodyTableStyle());
+					result.add(row);
+				}else{
+					result.add(row);
+				}
+			
+			}
+		} catch (SQLException e) {
+			e.printStackTrace();
+		}
+  
+		return result;
+	}
+
+    /**
+     * 获取数据库的所有表名及表的信息
+     * @return list
+     */
+    private static List<Map<String,String>> getTableName(ResultSet rs){
+    	List<Map<String,String>> list = new ArrayList<>();
+    	
+    	try {
+			while(rs.next()){
+				Map<String,String> result = new HashMap<>();
+				result.put("table_name", rs.getString("table_name")+"");
+				result.put("table_type", rs.getString("table_type")+"");
+				result.put("engine", rs.getString("engine")+"");
+				result.put("table_collation", rs.getString("table_collation")+"");
+				result.put("table_comment", rs.getString("table_comment")+"");
+				result.put("create_options", rs.getString("create_options")+"");
+				list.add(result);
+			}
+		} catch (SQLException e) {
+			e.printStackTrace();
+		}
+    	
+    	return list;
+    }
+
+}

File diff suppressed because it is too large
+ 11 - 0
src/main/java/com/msw/java/FileUtils.java


+ 21 - 0
src/main/java/com/msw/java/Main.java

@@ -0,0 +1,21 @@
+package com.msw.java;
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+public class Main extends Application{
+
+	@Override
+	public void start(Stage primaryStage) throws Exception {
+		Parent main = FXMLLoader.load(getClass().getResource("/main.fxml"));
+		primaryStage.setTitle("工具类");
+		primaryStage.setScene(new Scene(main));
+		primaryStage.show();
+	}
+    
+    public static void main(String[] args) {
+        launch(args);
+    }
+
+}

+ 250 - 0
src/main/java/com/msw/java/MainController.java

@@ -0,0 +1,250 @@
+package com.msw.java;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.collections.FXCollections;
+import javafx.event.ActionEvent;
+import javafx.fxml.FXML;
+import javafx.fxml.Initializable;
+import javafx.scene.control.Alert;
+import javafx.scene.control.Alert.AlertType;
+import javafx.scene.control.Button;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.Label;
+import javafx.scene.control.PasswordField;
+import javafx.scene.control.TextField;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.input.MouseEvent;
+import javafx.stage.DirectoryChooser;
+import javafx.stage.Stage;
+
+public class MainController implements Initializable{
+
+	@FXML
+	private Button testCon;
+	
+	@FXML
+	private Button exportWord;
+	
+	@FXML
+	private ChoiceBox<String> dbType;
+	
+	@FXML
+	private TextField username;
+	
+	@FXML
+	private TextField port;
+	
+	@FXML TextField host;
+	
+	@FXML
+	private PasswordField password;
+	
+	@FXML
+	private Label dirPath;
+	
+	@FXML
+	private Button choisePath;
+	
+	@FXML
+	private ImageView img;
+	
+	@FXML
+	private ChoiceBox<String> dbName;
+	
+	@FXML
+	private Label dbLabel;
+	
+	@Override
+	public void initialize(URL location, ResourceBundle resources) {
+		dbType.setItems(FXCollections.observableArrayList("mysql","oracle"));
+		dbType.getSelectionModel().select(0);
+		Image image = new Image("/head_2.jpg");
+		img.setImage(image);
+		dbType.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
+			@Override
+			public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
+				if("mysql".equals(newValue)){
+					dbName.setVisible(true);
+					dbLabel.setVisible(true);
+				}else if("oracle".equals(newValue)){
+					dbName.setVisible(false);
+					dbLabel.setVisible(false);
+				}
+			}
+		});
+	}
+	
+	public void dbTouch(MouseEvent event){
+		String type = dbType.getValue();
+		String user = username.getText();
+		String pwd = password.getText();
+		String value = dbName.getValue();
+		String p = port.getText();
+		String h = host.getText();
+		if(value!=null||"".equals(value)){
+			return ;
+		}
+		if("mysql".equals(type)){
+			Connection con = SqlUtils.getConnnection(String.format("jdbc:mysql://%s:%s",h,p),user, pwd);
+			if(con==null) {
+				Alerts(false,"connecting to database failed");
+				return ;
+			}
+			ResultSet set = SqlUtils.getResultSet(con, "show databases");
+			try {
+				List<String> list = new ArrayList<String>();
+				while(set.next()){
+					list.add(set.getString(1));
+				}
+				System.out.println(list.toString());
+				dbName.setItems(FXCollections.observableArrayList(list));
+			} catch (SQLException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+	
+	public void selectDirPath(ActionEvent event){
+		Stage mainStage = null;
+		DirectoryChooser directory = new DirectoryChooser();
+		directory.setTitle("选择路径");
+		File file = directory.showDialog(mainStage);
+		if(file!=null){
+			String path = file.getPath();
+			dirPath.setText(path);			
+		}
+	}
+	
+	public void typeTouch(MouseEvent event){
+		String value = dbType.getValue();
+		System.out.println(value);
+		if(value.equals("mysql")){
+			dbName.setVisible(true);
+		}
+		if(value.equals("oracle")){
+			dbName.setVisible(false);
+		}
+	}
+	
+	public void testCon(ActionEvent event){
+		isCon();
+	}
+	
+	public boolean isCon(){
+		String type = dbType.getValue();
+		String user = username.getText();
+		String pwd = password.getText();
+		String p = port.getText();
+		String h = host.getText();
+		if("mysql".equals(type)){
+			Connection con = SqlUtils.getConnnection(String.format("jdbc:mysql://%s:%s",h,p),user, pwd);
+			if(con!=null){
+				Alerts(true,"connected to database success");
+				return true;
+			}else{
+				Alerts(false,"connecting to database failed");
+				return false;
+			}
+		}
+		if("oracle".equals(type)){
+			Connection con = OracleUtils.getConnnection(String.format("jdbc:oracle:thin:@%s:%s:ORCL",h,p),user, pwd);
+			if(con!=null){
+				Alerts(true,"connected to database success");
+				return true;
+			}else{
+				Alerts(false,"connecting to database failed");
+				return false;
+			}
+		}
+		return false;
+	}
+	
+	public void exportDoc(ActionEvent event){
+		String type = dbType.getValue();
+		String user = username.getText();
+		String pwd = password.getText();
+		String dir = dirPath.getText();
+		String value = dbName.getValue();
+		String p = port.getText();
+		String h = host.getText();
+		if(dir.equals("未选择")){
+			Alerts(false, "请选择文件路径");
+			return;
+		}
+		Map<String,String> map = new HashMap<String,String>();
+		map.put("-t", type);
+		map.put("-u", user);
+		map.put("-p", pwd);
+		map.put("-d", dir);
+		map.put("-n", value);
+		map.put("p",p);
+		map.put("h",h);
+		if("mysql".equals(type)){
+			boolean b = check(map);
+			if(!b){
+				return ;
+			}
+			try {
+				App.MySQL(map);
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}else if("oracle".equals(type)){
+			try {
+				App.Oracle(map);
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+	
+	private static boolean check(Map<String,String> map){
+		if(!map.containsKey("-n")||map.get("-n")==null||map.get("-n").equals("")){
+    		Alerts(false,"请输入数据库名称!");
+    		return false;
+    	}
+    	if(!map.containsKey("-u")||map.get("-u")==null||map.get("-u").equals("")){
+    		Alerts(false,"请输入数据库用户名!");
+    		return false;
+    	}
+    	if(!map.containsKey("-p")||map.get("-p")==null||map.get("-p").equals("")){
+    		Alerts(false,"请输入数据库密码!");
+    		return false;
+    	}
+    	if(!map.containsKey("-d")||map.get("-d")==null||map.get("-d").equals("")){
+    		Alerts(false,"请输入保存文件的目录!");
+    		return false;
+    	}
+    	return true;
+	}
+	
+	
+	public static void Alerts(boolean is,String content){
+		Alert alert = new Alert(AlertType.INFORMATION);
+		if(is){
+			alert.setTitle("Dialog");	
+			alert.setHeaderText(null);
+			alert.setContentText(content);
+		}else{
+			alert.setTitle("Dialog");	
+			alert.setHeaderText(null);
+			alert.setContentText(content);
+		}
+		alert.showAndWait();
+	}
+
+}

+ 45 - 0
src/main/java/com/msw/java/OracleUtils.java

@@ -0,0 +1,45 @@
+package com.msw.java;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class OracleUtils {
+
+	private static String url = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
+	
+	static {
+		try {
+			Class.forName("oracle.jdbc.driver.OracleDriver");
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public static Connection getConnnection(String url,String user,String password){
+		try {
+			return DriverManager.getConnection(url, user, password);
+		} catch (SQLException e) {
+			System.out.println("ORA-01017: invalid username/password; logon denied");
+			return null;
+		}
+	}
+	
+	public static void closeConnection(Connection conn) throws SQLException{
+		if(conn!=null){
+			conn.close();			
+		}
+	}
+	
+	public static ResultSet getResultSet(Connection conn ,String sql){
+		try {
+			Statement stat = conn.createStatement();
+			return stat.executeQuery(sql);
+		} catch (SQLException e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+}

+ 37 - 0
src/main/java/com/msw/java/POITLStyle.java

@@ -0,0 +1,37 @@
+package com.msw.java;
+
+import com.deepoove.poi.data.style.Style;
+import com.deepoove.poi.data.style.TableStyle;
+
+public class POITLStyle {
+
+	public static Style getHeaderStyle(){
+		Style style = new Style();
+		style.setBold(true);
+		style.setFontSize(14);
+		style.setColor("000000");
+		style.setFontFamily("宋体");
+		return style;
+	}
+	
+	public static TableStyle getHeaderTableStyle(){
+		TableStyle style = new TableStyle();;
+		style.setBackgroundColor("B7B7B7");
+		return style;
+	}
+	
+	public static Style getBodyStyle(){
+		Style style = new Style();
+		style.setBold(false);
+		style.setFontSize(12);
+		style.setColor("000000");
+		style.setFontFamily("宋体");
+		return style;
+	}
+	
+	public static TableStyle getBodyTableStyle(){
+		TableStyle style = new TableStyle();;
+		style.setBackgroundColor("DEDEDE");
+		return style;
+	}
+}

+ 46 - 0
src/main/java/com/msw/java/SqlUtils.java

@@ -0,0 +1,46 @@
+package com.msw.java;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class SqlUtils {
+
+	private static String url = "jdbc:mysql://192.168.1.205:3306";
+	
+	static {
+		try {
+			Class.forName("com.mysql.jdbc.Driver");
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public static Connection getConnnection(String url, String user,String password){
+		try {
+			return DriverManager.getConnection(url, user, password);
+		} catch (SQLException e) {
+			e.printStackTrace();
+			System.out.println("Access denied for user (using password: NO)");
+			return null;
+		}
+	}
+
+	public static void closeConnection(Connection conn) throws SQLException{
+		if(conn!=null){
+			conn.close();			
+		}
+	}
+	
+	public static ResultSet getResultSet(Connection conn ,String sql){
+		try {
+			Statement stat = conn.createStatement();
+			return stat.executeQuery(sql);
+		} catch (SQLException e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+}

BIN
src/main/java/head_2.jpg


+ 78 - 0
src/main/java/main.fxml

@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.scene.image.*?>
+<?import javafx.scene.text.*?>
+<?import javafx.scene.control.*?>
+<?import java.lang.*?>
+<?import javafx.scene.layout.*?>
+
+<Pane fx:id="main" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.101" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.msw.java.MainController">
+   <children>
+      <Label layoutX="250.0" layoutY="155.0" text="用户名">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </Label>
+      <Label layoutX="250.0" layoutY="195.0" text="密    码">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </Label>
+      <Button fx:id="testCon" layoutX="285.0" layoutY="344.0" mnemonicParsing="false" onAction="#testCon" text="测试连接" />
+      <Button fx:id="exportWord" layoutX="406.0" layoutY="344.0" mnemonicParsing="false" onAction="#exportDoc" text="导出文档" />
+      <TextField fx:id="username" layoutX="322.0" layoutY="149.0">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </TextField>
+      <PasswordField fx:id="password" layoutX="322.0" layoutY="191.0">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </PasswordField>
+      <Label layoutX="250.0" layoutY="113.0" text="类    型">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </Label>
+      <ChoiceBox fx:id="dbType" layoutX="322.0" layoutY="111.0" prefHeight="23.0" prefWidth="189.0" />
+      <Label layoutX="250.0" layoutY="282.0" text="目    录">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </Label>
+      <Label fx:id="dirPath" layoutX="335.0" layoutY="282.0" text="未选择">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </Label>
+      <Button fx:id="choisePath" layoutX="310.0" layoutY="281.0" mnemonicParsing="false" onAction="#selectDirPath" prefHeight="23.0" prefWidth="5.0" text="选择路径" />
+      <ImageView fx:id="img" fitHeight="317.0" fitWidth="180.0" layoutX="25.0" layoutY="42.0" pickOnBounds="true" preserveRatio="true" />
+      <Label fx:id="dbLabel" layoutX="250.0" layoutY="238.0" text="数据库">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </Label>
+      <ChoiceBox fx:id="dbName" layoutX="322.0" layoutY="237.0" onMouseClicked="#dbTouch" prefHeight="23.0" prefWidth="189.0" />
+      <Label layoutX="248.0" layoutY="33.0" text="主    机">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </Label>
+      <Label layoutX="249.0" layoutY="73.0" text="端    口">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </Label>
+      <TextField fx:id="host" layoutX="321.0" layoutY="31.0">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </TextField>
+      <TextField fx:id="port" layoutX="321.0" layoutY="69.0">
+         <font>
+            <Font size="14.0" />
+         </font>
+      </TextField>
+   </children>
+</Pane>

Some files were not shown because too many files changed in this diff