本人写了一个小程序,从一个文本文档里把数据读入ORALCE数据库中,该文本文档有固定的格式,根据判断每行的头一个字符,从第19行开始读入数据,把第19行的1-10列和15-18列等等读入到数据库指定的表中,写到最后错误很多,头次学习往各位大虾帮个忙!!!!

解决方案 »

  1.   

    如果你知道第几列到第几列,那好办呀就是通过BufferedReader的readLine将数据一行一行读上来,再通过String.subString(int i1,int i2)来取具体的信息你可以查查api,这些方法说的很清楚的
      

  2.   

    package util;
    import java.io.*;
    import java.util.Vector;public class Jxsps {
        public Jxsps() {
            try {
                jbInit();
            } catch (Exception ex) {
                ex.printStackTrace();
            }    }
        class number {
        int ch;
        int str;
           }    public static void main(String[] args){
            String dbur1 = "jdbc:odbc:wtgsdb";
            File f = new File("e:/Gjzd17.S01");
            Vector v = new Vector();
                FileReader fr = null;
                try {
                    fr = new FileReader(f);
                    BufferedReader br = new BufferedReader(fr);            String line = null;
                try {
                    line = br.readLine();
                } catch (IOException ex1) {
                }
                while(line!=null){
                    v.add(line);
                    try {
                        line = br.readLine();
                    } catch (IOException ex2) {
                    }
                }            } catch (FileNotFoundException ex) {
                }
                 try{
                     line = br.readLine();
                    } catch (IOException ex3) {
                    wtgsdb.open;
                    str = null;
                    while   not   Eof(line);
                    Read(line,Ch);
                    if(ch!='S');
                    return line++;
                    else if(ch='S')
                         return str=str+ch;
                         SPSS.Append;
                         SPSS.Edit;
                         SPSS.FieldByName('hzb').AsString:= string.substring(Str,47,55);
                         SPSS.FieldByName('zzb').AsString:= string.substring(Str,56,65);
                         SPSS.FieldByName('dmgc').AsString:= string.substring(Str,66,71);
                         else if(ch<>char(13))
                         return line++;
                }
                for (int i=0;i<v.size();i++){
                System.out.println(v.get(i).toString());
                }        }    private void jbInit() throws Exception {
        }
    }高手帮看下,刚开始学,不太会写..错误不少!!!指点一下吧
      

  3.   

    我重装了系统
    还没Eclipse
    只是粗看了下
    SPSS.Append;//SPSS?是哪里来的?
    File f = new File("e:/Gjzd17.S01");//引用文件地址好象是e:\\Gjzd17.S01
    if(ch!='S');
    /**
    不知道你的ch是string还是char,要是string,则ch.qurel!="S"
    ch是引用
    */
    SPSS.FieldByName('hzb').AsString:= string.substring(Str,47,55);
    //这种语法,明显是delphi(pascal)的嘛
    //Java大小敏感String.subString(Str,47,55);
      

  4.   

    SPSS.FieldByName('hzb').AsString:= string.substring(Str,47,55);
    //这句话我知道不对,但是我还不知道怎么从一行里截取数据读入数据中
    SPSS.Append;//SPSS  是数据库wtgsdb中的一个表