当前位置: 代码迷 >> SQL >> java 去掉sql诠释 ""
  详细解决方案

java 去掉sql诠释 ""

热度:83   发布时间:2016-05-05 14:16:04.0
java 去掉sql注释 "--......"

写java代码,去掉sql中的注释.

录井任务.sql

select tsk.well_id,
       tsk.owner_org_id owner_id, ---业务ID
       to_char(tsk.start_pause_time1, 'yyyy-MM-dd') pause_start, --中停开始日期
       to_char(tsk.end_pause_time1, 'yyyy-MM-dd') pause_end, --中停结束日期
       tsk.geographic_location location, --地理位置
       tsk.enable_trans, -- 是否允许传输(0:不是;1:是)
       to_char(tsk.start_pause_time2, 'yyyy-MM-dd') pause_start2, --二次中停开始日期
       to_char(tsk.end_pause_time2, 'yyyy-MM-dd') pause_end2, -- 二次中停结束日期
       tsk.locked_if locked, ---是否锁定记录编辑
       tsk.had_trans, --- 是否远传了数据 0:否,1:是
       tsk.spare2 data_valid,
       tsk.spare1 batch_add,
       cotc.competenc_name team_competenc, -- 队伍资质名称
       substr(tsk.extra_item, 1, 1) ding_l_y_g_if, --是否定量银光
       substr(tsk.extra_item, 2, 1) heci_if, --- 是否核磁录井
       substr(tsk.extra_item, 3, 1) di_hua_if, -- 是否地化录井
       mw.record_no bwpk, --记录号
       mw.over_symbol over_tag, ---完钻标志
             cw.spud_in_date is null) and oil.bill_id is null)
 order by subg1.coding_show_id, mw.over_symbol, w.well_name

 

java类:

 

package com.yw.system.A7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Test {
 
 public static void main(String[] args){
  new Test().getSql();
 }

 private String getSql(){
  InputStream is = getClass().getResourceAsStream("/录井任务.sql");
  //File file = new File("/录井任务.sql");
        BufferedReader reader = null;
        StringBuffer sb = new StringBuffer();
        try {
            reader = new BufferedReader(new InputStreamReader(is));
            String tempString = null;
            int line = 1;
            while ((tempString = reader.readLine()) != null) {
                System.out.println("line " + line + ": " + tempString);//一行行的读
                sb.append(tempString.contains("--")?tempString.substring(0, tempString.indexOf("--")):tempString.substring(0));
                line++;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                 e1.printStackTrace();

                }
            }
        }
  
  return sb.toString();
  
 }
}

 


 

  相关解决方案