通过IO流进行文件的输入输出;
1) 点击确定,将SQL脚本(data.sql)读取并执行,然后结果返回到(out.txt)中去,
2)点击开始比对,把(out.txt)和(true.txt)进行比较,最后返回结果到(result.txt)中;
3)点击打开目录,可以打开相对路径;
输出结果同时显示在文本框中;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package swingsql;
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
*06
* @author Highgo
*/
public class NewJFrame extends javax.swing.JFrame {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/samp_db?serverTimezone=GMT";
// Database credentials
static String USER = "root";
static String PASS = "zyl123";
static final String FILE_PATH = "src/out.txt";
static final String COMPARED_FILE_PATH = "src/true.txt";
static final String RESULT_FILE_PATH = "src/result.txt";
static final String DATA_SQL = "src/data.sql";
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
this.setTitle("SwingSQL测试");
setLocationRelativeTo(null);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
text1User = new java.awt.TextField();
text2Password = new java.awt.TextField();
label1User = new java.awt.Label();
label2Password = new java.awt.Label();
textArea1 = new java.awt.TextArea();
label3Start = new java.awt.Label();
jButton1User = new javax.swing.JButton();
jButton2Password = new javax.swing.JButton();
jButton3Start = new javax.swing.JButton();