package com.example.kafka.utils;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
@SuppressWarnings("serial")
public class CreateSqlWin extends JFrame {
private JPanel contentPane;
private JTextField txtStr;
private JRadioButton rdbtnString;
private JRadioButton rdbtnStringbuffer;
private JSplitPane splitPane;
private JTextArea newSql;
private JTextArea oldSql;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CreateSqlWin frame = new CreateSqlWin();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public CreateSqlWin() {
setMinimumSize(new Dimension(840, 600));
setTitle("SQL转JAVA字符串");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 842, 605);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(10, 80));
contentPane.add(panel, BorderLayout.NORTH);
panel.setLayout(new BorderLayout(0, 0));
JPanel panel_1 = new JPanel();
panel_1.setBorder(new LineBorder(new Color(0, 0, 0)));
panel_1.setPreferredSize(new Dimension(300, 10));
panel.add(panel_1, BorderLayout.CENTER);
panel_1.setLayout(null);
JLabel label = new JLabel("选择生成方式:");
label.setBounds(10, 10, 153, 20);
panel_1.add(label);
rdbtnString = new JRadioButton("String");
rdbtnString.setSelected(true);
rdbtnString.setBounds(52, 36, 79, 23);
panel_1.add(rdbtnString);
rdbtnStringbuffer = new JRadioButton("StringBuffer");
rdbtnStringbuffer.setBounds(144, 36, 107, 23);
panel_1.add(rdbtnStringbuffer);
ButtonGroup bGroup = new ButtonGroup();
bGroup.add(rdbtnString);
bGroup.add(rdbtnStringbuffer);
txtStr = new JTextField();
txtStr.setText("str");
txtStr.setBounds(313, 31, 180, 33);
panel_1.add(txtStr);
txtStr.setColumns(10);
JLabel label_1 = new JLabel("输入变量名:");
label_1.setBounds(276, 13, 87, 15);
panel_1.add(label_1);
JPanel panel_3 = new JPanel();
panel_3.setBorder(new MatteBorder(1, 0, 1, 1, (Color) new Color(0, 0, 0)));
panel_3.setPreferredSize(new Dimension(200, 10));
panel.add(panel_3, BorderLayout.EAST);
panel_3.setLayout(new BorderLayout(0, 0));
JButton button = new JButton("生成");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//生成SQL
String oldSqlStr = oldSql.getText();
if(oldSqlStr.equals("")){
JOptionPane.showMessageDialog(CreateSqlWin.this, "请在左侧输入SQL再执行!");
return;
}
//清空
if(!newSql.getText().equals("")){
newSql.setText("");
}
String valibleName = txtStr.getText();
if(valibleName.trim().equals("")){
JOptionPane.showMessageDialog(CreateSqlWin.this, "请输入变量名!");
return;
}
String[] sqls = oldSqlStr.split("\n");
StringBuffer result = new StringBuffer();
//对SQL进行拼接
if(rdbtnString.isSelected()){
//string形式
for(int i=0;i<sqls.length-1;i++){
if(result.toString().equals("")){
result.append(valibleName+" = \" "+sqls[i]+" \"\n");
}
else {
result.append(" +\" "+sqls[i]+" \"\n");
}
}
result.append(" +\" "+sqls[sqls.length-1]+" \";\n");
}
else{
//string形式
for(int i=0;i<sqls.length;i++){
result.append(valibleName+".append(\" "+sqls[i]+" \");\n");
}
}
newSql.setText(result.toString());
}
});
button.setFont(new Font("楷体", Font.PLAIN, 32));
panel_3.add(button, BorderLayout.CENTER);
JPanel panel_2 = new JPanel();
panel_2.setBorder(new MatteBorder(0, 1, 1, 1, (Color) new Color(0, 0, 0)));
contentPane.add(panel_2, BorderLayout.CENTER);
panel_2.setLayout(new BorderLayout(0, 0));
splitPane = new JSplitPane();
splitPane.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
divider();
}
});
panel_2.add(splitPane, BorderLayout.CENTER);
JScrollPane scrollPane = new JScrollPane();
splitPane.setLeftComponent(scrollPane);
oldSql = new JTextArea();
scrollPane.setViewportView(oldSql);
JScrollPane scrollPane_1 = new JScrollPane();
splitPane.setRightComponent(scrollPane_1);
newSql = new JTextArea();
scrollPane_1.setViewportView(newSql);
JPanel panel_4 = new JPanel();
FlowLayout flowLayout = (FlowLayout) panel_4.getLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
panel_4.setPreferredSize(new Dimension(10, 30));
panel_2.add(panel_4, BorderLayout.NORTH);
JLabel lblsql = new JLabel("请在左侧输入你要格式化的SQL语句:");
lblsql.setHorizontalAlignment(SwingConstants.LEFT);
panel_4.add(lblsql);
}
public void divider(){
splitPane.setDividerLocation(0.4);
}
}
sql转换工具
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:扩展欧几里得算法
下一篇:汉诺塔--(数据结构)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
sql注入代码转换工具
从网上收集的工具!
代码 sql 工具 转换 注入 -
时间戳 转换工具
概述 UNIX 时间戳转换工具,可以将 UNIX 时间戳转换成标准格式的北京时间,也可以将标准格
UNIX 时间戳 unix perl -
springmvc动态生成接口
创建bean实例(createBeanInstance 方法)AbstractAutowireCapableBeanFactory 的 createBeanInstance 方法实现了创建 bean 的实例,将 BeanDefinition 转换为 BeanWrapper,转换是一个复杂的过程,大致步骤如下:1)、如果存在创建bean的回调方法,则从回调方法获取bean实例 BeanWrapper
springmvc动态生成接口 Spring 4.x 源码 创建bean实例 BeanWrapper 构造方法