文本:
 
中国有140000000人口,平均年龄78.3岁
有4个直辖市,
这里有14首歌,是5个人做的
日本有25000000人口,平均年龄80岁
有9个直辖市,
据悉,去年,福州国企共承接178项总投资1911亿元的投资项目。其中,交建集团、
城乡建总、水务投资、新榕城建和房地产发展集团等5家公司就承接了172项投资项
目,属于五大战役项目的63项,总投资1178亿元,分别占项目数和总投资的35.4%和
62%。
 现在已经可以运行打印出来,但还不清楚如何存入到oracle数据库中(存入格式为  第X行,第X个)。最近刚开始学基础的,很多都不会,汗
望高手能够帮忙解答下,谢谢~
付代码:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReadSelectedLine { 
static {
System.out.println("第X行\t第X个\t数字");
}
    static void readLineVarFile(String lineStr, int lineNumber) throws IOException { 
    StringBuffer strBuffer = new StringBuffer();
            int l = lineStr.length();
int indexpost = 0;
for(int i=0;i<l;i++){
int ca = lineStr.charAt(i);
    if((ca>47 && ca<58) || ca==46){
   strBuffer.append(String.valueOf(lineStr.charAt(i)));
}else{
   if(strBuffer!=null){
       String temp = strBuffer.toString();
   if(temp!=null && !"".equals(temp)){
  System.out.println(lineNumber+"\t"+(++indexpost)+"\t"+temp);
   }
   }
   strBuffer = new StringBuffer();
}
}
    }  
    // 文件内容的总行数。    
    static int getTotalLines(String fileName) throws IOException { 
            BufferedReader in = new BufferedReader(new InputStreamReader( 
                            new FileInputStream(fileName))); 
            LineNumberReader reader = new LineNumberReader(in); 
            String s = reader.readLine(); 
            int lines = 0; 
            while (s != null) { 
                    lines++; 
                    s = reader.readLine(); 
            } 
            reader.close(); 
            in.close(); 
            return lines; 
    } 
     
    public static void main(String[] args) throws IOException { 
             
            // 读取文件    
            String fileName = "d:/111.txt"; 
             
            // 获取文件的内容的总行数    
            int totalNo = getTotalLines(fileName); 
            //System.out.println("There are "+totalNo+ " lines in the text!"); 
             
            BufferedReader reader = new BufferedReader(new InputStreamReader( 
                    new FileInputStream(fileName)));
            String lineStr;
            for(int i=0;i<totalNo; i++){
             lineStr = reader.readLine(); 
             readLineVarFile(lineStr,i+1);
            }
                   
    } 

解决方案 »

  1.   

    既然你都打印出来了,难道不能用一个字符串拼接起来,拼接成功,成功后,写一个插入语句,楼主不会?我不信,JDBC会不?我不信楼主不会。
      

  2.   

    呃这个是请教别人的,目前也是没全部看懂,迷迷糊糊的。JDBC连接,百度过了,大概知道,还没连接过。请问是直接写SQL语句中的 Insert么最近一起学JAVA和ORACLE,几乎是从零开始,所以这些基础的,还真不怎么会望求指教,感激不尽~
      

  3.   

    呃这个是请教别人的,目前也是没全部看懂,迷迷糊糊的。JDBC连接,百度过了,大概知道,还没连接过。请问是直接写SQL语句中的 Insert么最近一起学JAVA和ORACLE,几乎是从零开始,所以这些基础的,还真不怎么会望求指教,感激不尽~