📄 mainframe.java
字号:
Box box3 = Box.createHorizontalBox();
Box box4 = Box.createHorizontalBox();
box4.add(jlabel);
box4.add(Box.createHorizontalStrut(34));
box4.add(field1);
Box box5 = Box.createHorizontalBox();
box5.add(jlabel1);
box5.add(Box.createHorizontalStrut(50));
box5.add(field2);
Box box6 = Box.createHorizontalBox();
box6.add(jlabel2);
box6.add(Box.createHorizontalStrut(44));
box6.add(field3);
Box box7 = Box.createHorizontalBox();
box7.add(jlabel3);
box7.add(Box.createHorizontalStrut(20));
box7.add(field4);
Box box8 = Box.createHorizontalBox();
box8.add(Box.createHorizontalStrut(40));
box8.add(jbutton);
box8.add(Box.createHorizontalStrut(30));
box8.add(jbutton1);
box8.add(Box.createHorizontalStrut(40));
Box box9 = Box.createVerticalBox();
box9.add(Box.createVerticalStrut(30));
box9.add(box4);
box9.add(Box.createVerticalStrut(25));
box9.add(box5);
box9.add(Box.createVerticalStrut(25));
box9.add(box6);
box9.add(Box.createVerticalStrut(25));
box9.add(box7);
box9.add(Box.createVerticalStrut(35));
box9.add(box8);
box9.add(Box.createVerticalStrut(30));
box3.add(Box.createHorizontalStrut(25));
box3.add(box9);
box3.add(Box.createHorizontalStrut(25));
dialog.getContentPane().add(box3);
}
class TextFieldDocumentListener implements DocumentListener
{
public void insertUpdate(DocumentEvent e) {
try {
Document doc = e.getDocument();
int docLength = doc.getLength();
path = doc.getText(0, docLength);
} catch (BadLocationException ex) {
path = null;
}
}
public void removeUpdate(DocumentEvent e) {
try {
Document doc = e.getDocument();
int docLength = doc.getLength();
path = doc.getText(0, docLength);
} catch (BadLocationException ex) {
path = null;
}
}
public void changedUpdate(DocumentEvent e) {
}
}
class ButtonActionListener implements ActionListener
{
public void actionPerformed(ActionEvent actionevent) {
if (actionevent.getActionCommand().equals("jButton1")) {
JFileChooser jfilechooser = new JFileChooser(System.getProperty("user.dir"));
jfilechooser.setMultiSelectionEnabled(false);
if (0 == jfilechooser.showOpenDialog(MainFrame.this)) {
File file = jfilechooser.getSelectedFile();
path = file.getPath();
jTextField1.setText(path);
}
} else if (actionevent.getActionCommand().equals("jButton2")) {
if (thread != null) {
if(isPause && pressed.equals("jButton2")){
isPause = false;
jButton2.setEnabled(false);
jButton5.setEnabled(true);
}
return;
}
setPressed("jButton2");
jButton2.setEnabled(false);
jButton5.setEnabled(true);
updateLines = 0;
deleteLines = 0;
tablepos = 0;
jProgressBar1.setValue(0);
jTable1.setModel(new DefaultTableModel(new Object[0][0], COLUMNNAMES));
thread = new Thread(MainFrame.this);
thread.start();
} else if (actionevent.getActionCommand().equals("jButton3")) {
if (thread != null) {
if(isPause && pressed.equals("jButton3")){
isPause = false;
jButton3.setEnabled(false);
jButton5.setEnabled(true);
}
return;
}
setPressed("jButton3");
jButton3.setEnabled(false);
jButton5.setEnabled(true);
updateLines = 0;
deleteLines = 0;
tablepos = 0;
jProgressBar1.setValue(0);
jTable1.setModel(new DefaultTableModel(new Object[0][0], COLUMNNAMES));
thread = new Thread(MainFrame.this);
thread.start();
} else if (actionevent.getActionCommand().equals("jButton4")) {
field1.setText(driver);
field2.setText(url);
field3.setText(user);
field4.setText(password);
dialog.setSize(500, 300);
dialog.setResizable(false);
dialog.setVisible(true);
} else if (actionevent.getActionCommand().equals("jButton5")) {
if(thread != null){
isPause = true;
if (pressed.equals("jButton2")) {
jButton2.setEnabled(true);
}
if (pressed.equals("jButton3")) {
jButton3.setEnabled(true);
}
jButton5.setEnabled(false);
}
} else if (actionevent.getActionCommand().equals("button1")) {
driver = field1.getText();
url = field2.getText();
user = field3.getText();
password = field4.getText();
Properties properties = new Properties();
properties.put("driver", driver);
properties.put("url", url);
properties.put("user", user);
properties.put("password", password);
properties.put(FIELDNAMES[0],fieldNames.get(FIELDNAMES[0]));
properties.put(FIELDNAMES[1],fieldNames.get(FIELDNAMES[1]));
properties.put(FIELDNAMES[2],fieldNames.get(FIELDNAMES[2]));
properties.put(FIELDNAMES[3],fieldNames.get(FIELDNAMES[3]));
properties.put(FIELDNAMES[4],fieldNames.get(FIELDNAMES[4]));
properties.put(FIELDNAMES[5],fieldNames.get(FIELDNAMES[5]));
properties.put(FIELDNAMES[6],fieldNames.get(FIELDNAMES[6]));
properties.put(FIELDNAMES[7],fieldNames.get(FIELDNAMES[7]));
properties.put(FIELDNAMES[8],fieldNames.get(FIELDNAMES[8]));
BufferedOutputStream bufferedoutputstream = null;
try {
bufferedoutputstream = new BufferedOutputStream(new FileOutputStream("com\\hwj\\tool\\dbconn.properties"));
properties.store(bufferedoutputstream, "db connection properties configure ");
bufferedoutputstream.close();
} catch (Exception exception) {
exception.printStackTrace();
bufferedoutputstream = null;
}
dialog.dispose();
} else if (actionevent.getActionCommand().equals("button2")) {
dialog.dispose();
}
}
}
public void run()
{
starttime = System.currentTimeMillis();
BufferedReader br = null;
try {
ArrayList arraylist = new ArrayList(40000);
if (path == null || path.trim().equals("")) {
throw new IllegalStateException("未选择文件");
}
if (driver == null || driver.trim().equals("")
|| url == null || url.trim().equals("")) {
throw new IllegalStateException("数据库连接参数未设置");
}
br = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
Connection connection = getConnection(driver, url, user, password);
Statement statement = connection.createStatement();
String partyQuery = "select "+(String)fieldNames.get(FIELDNAMES[0])+" from "+(String)fieldNames.get(FIELDNAMES[7])+" where "+(String)fieldNames.get(FIELDNAMES[6])+" = 'B'";
//System.out.println("partyQuery is:"+partyQuery);
ResultSet resultset = statement.executeQuery(partyQuery);
do {
if (!resultset.next()) {
break;
}
String s = resultset.getString(FIELDNAMES[0]);
if (s != null && !s.trim().equals("")) {
arraylist.add(s.trim());
}
} while (true);
resultset.close();
char[] ac = new char[856];
String s1 = "jButton2";
String s2 = "jButton3";
int progress = 0;
int i = 856;
while(true)
{
while (!isPause) {
i = br.read(ac, 0, 856);
if (i < 856) {
break;
}
String s3 = new String(ac);
String s4 = s3.substring(3, 14).trim();
String s5 = s3.substring(224, 228).trim();
long costTime = (System.currentTimeMillis() - starttime) / 1000L;
if(totallength >0)
{
progress = (int)(((float)updateLines / totallength)*100);
}
else
{
int totalTime = 1;
if(pressed.equals(s1))
{
totalTime = 420;
}
else
{
totalTime = 2400;
}
progress = (int)(((float)costTime/totalTime)*100);
}
jProgressBar1.setValue(progress);
if (s5.equals("BANK")) {
String s6 = s3.substring(14, 119).trim();
String s7 = s3.substring(189, 224).trim();
String s8 = s3.substring(323, 358).trim() + " " + s3.substring(358, 393).trim() + " " + s3.substring(393, 463).trim();
String s9 = s3.substring(568, 638).trim();
String s10 = s3.substring(0, 3);
if (pressed.equals(s1)) {
procBank(s10, s4, s6, s8 + " " + s7 + "," + s9, arraylist);
}
if (pressed.equals(s2)) {
procBank2(s10, s4, s6, s8 + " " + s7 + "," + s9, arraylist, statement);
}
}
String labelString = null;
if(pressed.equals(s1)){
labelString = "存在" + updateLines + " 条需要更新的信息 "+deleteLines+" 条需要删除的信息 已用时" + costTime + "秒";
}
if(pressed.equals(s2)){
labelString = "已更新" + updateLines + " 条信息 已删除"+deleteLines+ "条信息 已用时" + costTime + "秒";
}
jLabel1.setText(labelString);
}
if (i < 856) {
break;
}
Thread.sleep(100);
}
br.close();
resultset.close();
statement.close();
connection.close();
if(progress<100)
{
jProgressBar1.setValue(100);
}
if (pressed.equals(s1)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -