package importtest;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JTextField;
import javax.swing.JFileChooser;
import javax.swing.JMenuBar;
import javax.swing.JButton;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.io.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame implements Runnable{
static FindProperty findProperty;
int badrownum=0;
int theday;
String path;
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JMenuBar jMenuBar1 = new JMenuBar();
JMenuBar jMenuBar2 = new JMenuBar();
JMenuBar jMenuBar3 = new JMenuBar();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel3 = new JLabel();
JComboBox jComboBox2 = new JComboBox();
JLabel jLabel4 = new JLabel();
JComboBox jComboBox3 = new JComboBox();
JLabel jLabel5 = new JLabel();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JLabel jLabel6 = new JLabel();
JComboBox jComboBox4 = new JComboBox();
JComboBox jComboBox5 = new JComboBox();
JLabel jLabel7 = new JLabel();
JComboBox jComboBox6 = new JComboBox();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JTextArea jTextArea1 = new JTextArea();
JScrollPane jScrollPane1 = new JScrollPane();
JButton jButton2 = new JButton();
JLabel jLabel10 = new JLabel();
JLabel jLabel11 = new JLabel();
JLabel jLabel12 = new JLabel();
JLabel jLabel13 = new JLabel();
JLabel jLabel14 = new JLabel();
JLabel jLabel15 = new JLabel();
JLabel jLabel16 = new JLabel();
JLabel jLabel17 = new JLabel();
JLabel jLabel18 = new JLabel();
JLabel jLabel19 = new JLabel();
JComboBox jComboBox7 = new JComboBox();
JComboBox jComboBox8 = new JComboBox();
JComboBox jComboBox9 = new JComboBox();
JComboBox jComboBox10 = new JComboBox();
JComboBox jComboBox11 = new JComboBox();
JComboBox jComboBox12 = new JComboBox();
public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
public int checkrownum(String badfilepath){
try {
File file=new File(badfilepath); //filepath为文件路径,自己写
if( file.exists()){
FileReader fr = new FileReader(file);
BufferedReader br1 = new BufferedReader(fr);
String line1="";
int lineNum=0;
while((line1=br1.readLine())!=null){
//System.out.println(line1);
lineNum++;
}
br1.close();
fr.close();
return lineNum; }
} catch (IOException ex) {
ex.printStackTrace(); }
return 0;
}
public void run(){
try {
jLabel11.setText("读取数据文件信息...");
File file=new File(path); //filepath为文件路径,自己写
FileReader fr = new FileReader(file);
BufferedReader br1 = new BufferedReader(fr);
String line1="";
int lineNum=0;
while((line1=br1.readLine())!=null){
//System.out.println(line1);
lineNum++;
}
br1.close();
fr.close();
jLabel11.setText("连接数据库中");
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
con=CreateConnection();
try {
stmt=con.createStatement();
} catch (SQLException ex1) {
}
if(con!=null){ jLabel11.setText("连接数据库成功!");}else{System.out.println("nnnnnnnnnnnnnnnn");}
String begindate=jComboBox1.getSelectedItem().toString()+"-"+jComboBox2.getSelectedItem().toString()+"-"+
jComboBox3.getSelectedItem().toString()+"-"+
jComboBox4.getSelectedItem().toString()+"-"+jComboBox5.getSelectedItem().toString()+"-"+
jComboBox6.getSelectedItem().toString();
String enddate=jComboBox7.getSelectedItem().toString()+"-"+jComboBox8.getSelectedItem().toString()+"-"+
jComboBox9.getSelectedItem().toString()+"-"+
jComboBox10.getSelectedItem().toString()+"-"+jComboBox11.getSelectedItem().toString()+"-"+
jComboBox12.getSelectedItem().toString();
System.out.println(begindate);
String sql="insert into xrmbat112(dnindex,dccontent,ddbegindate,ddenddate) values(xrmbat112_seq.nextval,'"+jTextArea1.getText()+"',to_date('"+begindate+"','yyyy-mm-dd-hh24-mi-ss'),to_date('"+enddate+"','yyyy-mm-dd-hh24-mi-ss'))";
stmt.executeUpdate(sql);
try { FileOutputStream fos = new FileOutputStream(
".//yuanshi.ctl");
fos.write("load data \n".getBytes());
fos.write(("infile '" + jTextField1.getText() + "'\n").
getBytes());
fos.write("APPEND into table xrmbat111 \n".
getBytes());
fos.write("fields terminated by whitespace \n".getBytes());
fos.write("(dcphonenumber,dnindex RECNUM) \n".getBytes());
jLabel11.setText("正在导入中...");
fos.close();
} catch (IOException ex) {
}
String badfilename=time();
String cmd="sqlldr userid="+findProperty.getPorperty("userid")+"/"+findProperty.getPorperty("password")+
"@"+findProperty.getPorperty("dbsname")+" control=./yuanshi.ctl bad=./baddata/"+badfilename+".txt";
System.out.print(cmd);
Process ldr=Runtime.getRuntime().exec(cmd);
InputStream stderr = ldr.getInputStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( br.readLine() != null){
line = br.readLine();
System.out.println(line);
badrownum=badrownum+1;
if(line!=null){
if(line.indexOf("数")!=-1){
jLabel12.setText("正在导入!已导入"+line.substring(line.indexOf("数"),line.length())+"行");
}
}
jLabel11.setText("导入中....");}