SQLCode.java
上传用户:quasar007
上传日期:2022-08-11
资源大小:4067k
文件大小:1k
源码类别:

企业管理

开发平台:

Java

  1. package com.tool;
  2. public final class SQLCode {
  3.   private static SQLCode sqlCode = null;
  4.   private static java.util.Properties sqlCodeProperties = new java.util.
  5.       Properties();
  6.   static {
  7.     sqlCode = new SQLCode();
  8.   }
  9.   private SQLCode() {
  10.     _load();
  11.   }
  12.   //取得sqlcode.properties中的sql语句
  13.   public static String getSQLCode(String sqlKey) {
  14.     String sql = "";
  15.     if (sqlCodeProperties.containsKey(sqlKey)) {
  16.       sql = sqlCodeProperties.getProperty(sqlKey);
  17.     }
  18.     return sql;
  19.   }
  20.   public static SQLCode getInstance() {
  21.     return sqlCode;
  22.   }
  23.   //指向sqlcode.properties的位置
  24.   public void _load() {
  25.     String fileName = "/com/tool/sqlCode.properties";
  26.     //通过指定路径找到资源文件存放在fileName中
  27.     sqlCodeProperties.clear();
  28.     //sqlCodeProperties清空
  29.     try {
  30.       java.io.InputStream in = null;
  31.       try {
  32.         in = getClass().getResourceAsStream(fileName);
  33.         //把fileName中存放值放入in字符流中
  34.         sqlCodeProperties.load(in);
  35.       }
  36.       finally {
  37.         in.close();
  38.       }
  39.     }
  40.     catch (java.io.IOException e) {
  41.       System.out.println(e.getMessage());
  42.     }
  43.   }
  44. }