⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runcourse.java

📁 java 读写EXCEL文件的源码
💻 JAVA
字号:
/********************************************************************
 *
 * $RCSfile: runCourse.java,v $  $Revision: 1.1 $  $Date: 2003/09/22 08:06:24 $
 *
 * $Log: runCourse.java,v $
 * Revision 1.1  2003/09/22 08:06:24  icestone
 * init
 *
 *
 *
 **********************************************************************/
package pcdmupgradedata;

 /**
 *  读脚本文件并执行建库
 *  使用LineNumberReader对象,而非BufferedReader对象
 **/

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.net.*;
import java.io.*;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java	    .io		.BufferedReader;
import java	    .io		.BufferedWriter;
import java	    .io		.File;
import java	    .io		.IOException;
import java.util.*;



 public class  runCourse implements Runnable{
  Connection conn;
  JLabel jLabel1;
  JLabel jLabel3;
  JLabel jLabel4;
  JLabel jLabel8;
  JLabel jLabel9;
  String filePath;
  JProgressBar jProgressBar1;
  String areaCode;
  JPanel jPanel1;
  JPanel jPanel2;
  int selectValue=0;
  private int curryCv;
  JFrame frame1;

 public runCourse
  (
  Connection conn,
  JLabel jLabel1,
  JProgressBar jProgressBar1,
  JPanel jPanel1,
  JPanel jPanel2,
  String  areaCode,
  String filePath,
  JLabel jLabel3,
  JLabel jLabel4,
  JLabel jLabel8,
  JLabel jLabel9,
  JFrame frame1
    ){

      this.conn=conn;
      this.jLabel1=jLabel1;
      this.filePath=filePath;
      this.jProgressBar1=jProgressBar1;
      this.jPanel1=jPanel1;
      this.jPanel2=jPanel2;
      this.areaCode=areaCode;
      this.jLabel3=jLabel3;
      this.jLabel4=jLabel4;
      this.jLabel8=jLabel8;
      this.jLabel9=jLabel9;
      this.frame1=frame1;

   }

    public void run()
     {
       String rdfile;
       /*空串判断*/
       String rdfile_j="";
       int pValue=0;
       boolean sep_flag=false;
       String exString="";

       try{
  	    Statement updateStatement = conn.createStatement();

            LineNumberReader out1 = new LineNumberReader
                                   (new InputStreamReader
                                   (new FileInputStream(filePath)));
            jLabel4.setVisible(true);
             /*加上对空格行的控制*/
            while((rdfile=out1.readLine()) != null) {
              rdfile_j=rdfile_j+rdfile;

              if(((rdfile_j.trim()).length()>0)){
Debug.print("rdfile==="+rdfile.length());

                pValue=out1.getLineNumber();
                jLabel1.setText("正在创建:"+rdfile);
                jProgressBar1.setValue(pValue);
                if((rdfile.trim()).equals(Const.SEPARATOR_FLAG))
                   {
                     sep_flag=true;
                     continue;
                   }
                 /*从指定位置读起*/
                if(rdfile.equals("")||pValue<(Integer.valueOf(RWConfig.ReadControl())).intValue()+1)continue;

                     if(sep_flag==true)
                       {
                         if(rdfile.equals("/")||rdfile.equals(";")) {
Debug.print("exString1==="+exString);
                            updateStatement.executeUpdate(exString);
                            exString="";
                            }
                         else
                            exString+=" "+rdfile;//空格分开脚本语句
                        }
                      else
                          updateStatement.executeUpdate(rdfile);
Debug.print("exString1==="+exString);

               /*写控制行*/
                if(sep_flag==false)
                   RWConfig.writeControl(String.valueOf(pValue));
                else if(sep_flag==true&&rdfile.equals("/"))
                 {
                   RWConfig.writeControl(String.valueOf(pValue));
                  }
                else{}
                curryCv=pValue;
               }//end if
           /*空串值还原*/
            rdfile_j="";
           }//end while
           out1.close();
           updateStatement.close();
          /**转换控制分隔*/
           if((Integer.valueOf(RWConfig.ReadControl())).intValue()<5000)
           {
                  RWConfig.writeControl(String.valueOf(5000));
           }
           /*增加管孔坐标转换的控制*/
            jLabel4.setVisible(false);
            jLabel8.setVisible(true);
//System.exit(0);
           transferChang.UpdateLoop(conn,areaCode,jProgressBar1,jLabel1,jLabel3);

       }//end try
         catch (ArrayIndexOutOfBoundsException ae)//vector throw exception
          {
           }
         catch (java.sql.SQLException se)
          {
             /*给判断是否跳出*/
              selectValue=JOptionPane.showConfirmDialog(frame1, "数据库操作错误!忽略错误继续转换吗\n"+se,"错误",JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
              if(selectValue==JOptionPane.YES_OPTION)
                 {
                  RWConfig.writeControl(String.valueOf(curryCv+2));
                  run();
                 }
              else
                {
                  System.exit(0);
                }
           }
        catch ( FileNotFoundException fe) {
               JOptionPane.showConfirmDialog(frame1, "脚本文件丢失!"+fe, "错误", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
             }//end try
        catch ( IOException ioe) {
               System.err.println(ioe.toString());
            }

            /*第二个文件insert new table*/
            jLabel8.setVisible(false);
            jLabel9.setVisible(true);

          jProgressBar1.setValue(jProgressBar1.getValue()+1000);
          /**完成后可能需运行的脚本*/
          ReadInsertFile(Const.PD_INSERTDATA);

          jProgressBar1.setValue(15000);
          JOptionPane.showMessageDialog(frame1,"选择完成按钮完成转换!无法转换的错误记录在:\n"+Const.ERROR_PATH);
          /**完成前标志*/
          RWConfig.writeControl(Const.BEFORE_FINISH_FLAG);
          jPanel1.setVisible(false);
          jPanel2.setVisible(true);


      }//end run

   private void ReadInsertFile(String insertFile){

       int pValue=0;
       String _rdfile=null;
       int _curryCv=(Integer.valueOf(RWConfig.ReadControl())).intValue();
       try{
  	    Statement updateStatement = conn.createStatement();

            LineNumberReader out1 = new LineNumberReader
                                   (new InputStreamReader
                                   (new FileInputStream(insertFile)));


            while((_rdfile=out1.readLine()) != null) {

                pValue=out1.getLineNumber();
                jLabel1.setText("得到新数据:"+_rdfile);
                if(_rdfile.equals("")||pValue<(((Integer.valueOf(RWConfig.ReadControl())).intValue()+1)-10000))continue;
                updateStatement.executeUpdate(_rdfile);
                RWConfig.writeControl(String.valueOf((10000+pValue)));
                _curryCv=10000+pValue;

               }//end while
           out1.close();
           updateStatement.close();
   	}//end try
        catch (java.sql.SQLException se)
          {
              selectValue=JOptionPane.showConfirmDialog(frame1, "数据库操作错误!忽略错误继续转换吗\n"+se,"错误",JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
              if(selectValue==JOptionPane.YES_OPTION)
                 {
                  RWConfig.writeControl(String.valueOf(_curryCv+2));
                  run();
                 }
              else
                {
                  System.exit(0);
                }
           }
        catch ( FileNotFoundException fe) {
               JOptionPane.showConfirmDialog(frame1, "脚本文件丢失!"+fe, "错误", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);

             }//end try
        catch ( IOException ioe) {
               System.err.println(ioe.toString());
            }
     }//end read2

/**
*删除用户sa操作
**/

   private void ReaddropFile(String dropFile,Connection con1){

       String d_rdfile=null;
       try{
  	    Statement updateStatement = con1.createStatement();

            LineNumberReader out1 = new LineNumberReader
                                   (new InputStreamReader
                                   (new FileInputStream(dropFile)));


            while((d_rdfile=out1.readLine()) != null) {
                if(d_rdfile.equals(""))continue;
                  updateStatement.executeUpdate(d_rdfile);
               }//end while
           out1.close();
           updateStatement.close();
   	}//end try
        catch (java.sql.SQLException se)
          {
//              selectValue=JOptionPane.showConfirmDialog(null, "数据库操作错误!忽略错误继续转换吗\n"+se,"错误",JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
//                  System.exit(0);
           }
        catch ( FileNotFoundException fe) {
               JOptionPane.showConfirmDialog(frame1, "脚本文件丢失!"+fe, "错误", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);

             }//end try
        catch ( IOException ioe) {
               System.err.println(ioe.toString());
            }
     }//end ReaddropFile



  }//end class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -