?? educesql_fpg.java
字號:
package gongju;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
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.text.DecimalFormat;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
// 基本版的改版,以適合公司用
public class Educesql_fpg extends javax.swing.JFrame {
private JPanel jPanel1;
private JTextArea txtMsg;
private JButton btnEDUCE;
private JLabel labTABLE;
private JTextField txtTABLE;
// private final String sql_column_name = "select distinct column_name from
// all_tab_cols where table_name=?";
// 防止有多個用戶下的表列不同而會報出“列名無效”的錯,修改為取當前用戶下表的列
private final String sql_column_name = "select distinct column_name from user_tab_cols where table_name=?";
private String str_table = "";
private Vector vec_column_name;
private StringBuffer errmsg = new StringBuffer();
private String username;
private String password;
private String host;
private String port;
private String sid;
private String temp_username;
private String temp_password;
private String temp_host;
private String temp_port;
private String temp_sid;
private JLabel labHost;
private JTextField txtHost;
private JButton btnTest;
private JScrollPane jScrollPane2;
private JTextPane txtCondition;
private JLabel labCondition;
private JTextField txtPort;
private JLabel labPort;
private JTextField txtSid;
private JLabel labSid;
private JButton btnView;
private JScrollPane jScrollPane1;
private JTextField txtPassword;
private JLabel labPassword;
private JTextField txtUsername;
private JLabel labUsername;
private Connection con = null;
private String before = "";
private String after = "";
private FileOutputStream fostream;
private BufferedReader input;
private String filepath;
private String condition;
private int checkcondition = 0;
private boolean checkcon = true;
private JCheckBox chkTxemp;
private JCheckBox chkCo;
private JPanel panTime;
private int checkconn = 0;
PreparedStatement ps_column = null;
private Showtime showtime;
private String txemp = "";
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
Educesql_fpg inst = new Educesql_fpg();
inst.setVisible(true);
}
public Educesql_fpg() {
super("Educesql_fpg");
initGUI();
Exit();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.setLayout(null);
jPanel1.setPreferredSize(new java.awt.Dimension(553, 182));
{
txtTABLE = new JTextField();
jPanel1.add(txtTABLE);
txtTABLE.setBounds(84, 49, 126, 28);
txtTABLE.setFont(new java.awt.Font("Tahoma", 0, 20));
txtTABLE.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent evt) {
if (evt.getKeyCode() == 10) {
generatesql();
}
}
});
}
{
labTABLE = new JLabel();
jPanel1.add(labTABLE);
labTABLE.setText("Table");
labTABLE.setBounds(14, 49, 63, 28);
}
{
btnEDUCE = new JButton();
jPanel1.add(btnEDUCE);
btnEDUCE.setText("\u5bfc\u51fa");
btnEDUCE.setBounds(224, 91, 63, 28);
btnEDUCE.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
generatesql();
}
});
}
{
labUsername = new JLabel();
jPanel1.add(labUsername);
labUsername.setText("Username");
labUsername.setBounds(14, 14, 63, 28);
}
{
txtUsername = new JTextField();
jPanel1.add(txtUsername);
txtUsername.setBounds(84, 14, 84, 28);
txtUsername.setFont(new java.awt.Font("Tahoma", 0, 20));
}
{
labPassword = new JLabel();
jPanel1.add(labPassword);
labPassword.setText("Password");
labPassword.setBounds(182, 14, 63, 28);
}
{
txtPassword = new JTextField();
jPanel1.add(txtPassword);
txtPassword.setBounds(245, 14, 84, 28);
txtPassword.setFont(new java.awt.Font("Tahoma", 0, 20));
}
{
jScrollPane1 = new JScrollPane();
jPanel1.add(jScrollPane1);
jScrollPane1.setBounds(14, 91, 196, 35);
{
txtMsg = new JTextArea();
jScrollPane1.setViewportView(txtMsg);
txtMsg.setBounds(16, 65, 129, 32);
}
}
{
btnView = new JButton();
jPanel1.add(btnView);
btnView.setText("\u67e5\u770b");
btnView.setBounds(294, 91, 63, 28);
btnView.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// 打開生成的sql
Runtime rt = Runtime.getRuntime();
try {
rt
.exec("CMD /C"
+ filepath.replace("//", "\\"));
txtMsg
.append("\n\u6253\u5f00\u6587\u4ef6\u6210\u529f");// 打開文件成功
} catch (Exception e) {
txtMsg
.setText("\n\u6253\u5f00\u6587\u4ef6\u5931\u8d25");// 打開文件失敗
rt.gc();
}
}
});
}
{
txtHost = new JTextField();
jPanel1.add(txtHost);
txtHost.setBounds(420, 14, 119, 28);
txtHost.setText("172.21.2.33");
txtHost.setFont(new java.awt.Font("Tahoma", 0, 20));
}
{
labHost = new JLabel();
jPanel1.add(labHost);
labHost.setText("HOST");
labHost.setBounds(371, 14, 49, 28);
}
{
labSid = new JLabel();
jPanel1.add(labSid);
labSid.setText("SID");
labSid.setBounds(371, 91, 42, 28);
}
{
txtSid = new JTextField();
jPanel1.add(txtSid);
txtSid.setBounds(420, 91, 119, 28);
txtSid.setText("fpg100t");
txtSid.setFont(new java.awt.Font("Tahoma", 0, 20));
}
{
labPort = new JLabel();
jPanel1.add(labPort);
labPort.setText("Port");
labPort.setBounds(371, 56, 49, 28);
}
{
txtPort = new JTextField();
jPanel1.add(txtPort);
txtPort.setBounds(420, 56, 119, 28);
txtPort.setText("1521");
txtPort.setFont(new java.awt.Font("Tahoma", 0, 20));
}
{
labCondition = new JLabel();
jPanel1.add(labCondition);
labCondition.setText("Condition");
labCondition.setBounds(21, 133, 77, 35);
}
{
jScrollPane2 = new JScrollPane();
jPanel1.add(jScrollPane2);
jScrollPane2.setBounds(98, 133, 301, 35);
{
txtCondition = new JTextPane();
jScrollPane2.setViewportView(txtCondition);
txtCondition.setBounds(98, 98, 266, 35);
txtCondition.setText("只需要輸入條件,前面不用加where");
txtCondition.setFont(new java.awt.Font("宋體", 0, 18));
// txtCondition.setFont(new
// java.awt.Font("Tahoma",0,20));
txtCondition.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent evt) {
if (checkcondition == 0) {
txtCondition.setText("");
checkcondition = 1;
}
}
});
}
}
{
btnTest = new JButton();
jPanel1.add(btnTest);
btnTest.setText("\u6d4b\u8bd5\u6570\u636e\u5e93");
btnTest.setBounds(224, 49, 133, 28);
btnTest.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
close();
if (Conn()) {
txtMsg.setText("連接數據庫正常!!!");
} else {
txtMsg.setText("連接數據庫失敗!!!");
}
}
});
}
{
panTime = new JPanel();
BorderLayout panTimeLayout = new BorderLayout();
jPanel1.add(panTime);
panTime.setBounds(448, 126, 91, 42);
panTime.setLayout(panTimeLayout);
showtime = new Showtime();
showtime.jTextPane1
.setPreferredSize(new java.awt.Dimension(96, 42));
showtime.jTextPane1.setFont(new java.awt.Font("Tahoma", 0,
16));
panTime.add(showtime, BorderLayout.CENTER);
}
{
chkCo = new JCheckBox();
jPanel1.add(chkCo);
chkCo.setBounds(42, 175, 168, 21);
chkCo.setText("\u5c06\u516c\u53f8\u66ff\u63db\u70ba'X'");
}
{
chkTxemp = new JCheckBox();
jPanel1.add(chkTxemp);
chkTxemp
.setText("\u5c07\u7570\u52d5\u4eba\u54e1\u66ff\u63db\u70ba\u672c\u6a5f\u80fd\u4eba\u54e1");
chkTxemp.setBounds(252, 175, 231, 21);
}
}
pack();
this.setSize(558, 244);
} catch (Exception e) {
e.printStackTrace();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -