JDBC測試用例

 package com;
 import java.io.FileWriter;
import java.io.IOException;
import java.sql.*;
import java.util.Date;
      
    public class jdbcMain {  
      
     public static void main(String[] args) throws IOException {  
      ResultSet rs = null;  
      Statement stmt = null;  
      Connection conn = null;  
      try {  
       Class.forName("oracle.jdbc.driver.OracleDriver");  
       Long s = System.currentTimeMillis();
       conn = DriverManager.getConnection("jdbc:oracle:thin:@181.18.18.12:1521:yf", "BJPOSV", "bjposvjbr01");  
       Long e = System.currentTimeMillis();
       System.out.println((e-s)+"毫秒");
       stmt = conn.createStatement();  
       rs = stmt.executeQuery("select * from TBL_INF_INS_INF t where t.REC_ST='1' ");
       int n=0;
       FileWriter writer = new FileWriter("D:\\be10M.sql");
//       try {
       while(rs.next()) {
        n++;
        System.out.println( "insert into INS_PROFITRATIO values(seq_yf_gen.nextval,'"+rs.getString(1)+"','34','68','108','68','108','26','73','CSPOSV',null,'N',null,'7','N','N');");
//        str.append("'"+rs.getString(1)+"',");
        /*String str = "insert into ins_profitSum values('"+rs.getString(1)+"','"+rs.getString(2)+"','"+rs.getString(3)+"','"+rs.getString(4)+"','"+rs.getString(5)+"','"+rs.getString(6)+"','"+rs.getString(7)+"','"+rs.getString(8)+"','"+rs.getString(9)+"','"+rs.getString(10)+"','"+rs.getString(11)+"',"+rs.getString(12)+",null,'"+rs.getString(14)+"'," +
      "null,null,'0.0','0.0','0.0','0.0','0.0',0,'0.0','0.0','0.0','0.0');\r\n";
               writer.write(str);
               writer.flush();*/
       }  
//       } catch (IOException a) {
//        a.printStackTrace();
//       }finally {
//        writer.close();
//       }
       System.out.println("*************************結束列表"+n);
      } catch (ClassNotFoundException e) {  
       e.printStackTrace();  
      } catch (SQLException e) {  
       e.printStackTrace();  
      } finally {  
       try {  
        if(rs != null) {  
         rs.close();  
         rs = null;  
        }  
        if(stmt != null) {  
         stmt.close();  
         stmt = null;  
        }  
        if(conn != null) {  
         conn.close();  
         conn = null;  
        }  
       } catch (SQLException e) {  
        e.printStackTrace();  
       }  
      }  
     }  
      
    }
相關文章
相關標籤/搜索