java使用cache数据库(一)

新建examjdbc.properties配置驱动信息

driver =com.intersys.jdbc.CacheDriver
url =jdbc:Cache://127.0.0.1:1972/USER
username =_system
password =123456

 

新建jdbc驱动加载文件 

ExamHisJDBCUtils.java
public class ExamHisJDBCUtils {

    private static final Logger LOGGER = Logger.getLogger(ExamHisJDBCUtils.class);
    private static Properties props = new Properties();

    private static String driver = null;
    private static String url = null;
    private static String username = null;
    private static String password = null;

    static {
        try {
            InputStream tempIn = ExamHisJDBCUtils.class
                    .getResourceAsStream("/examjdbc.properties");
            props.load(tempIn);

            driver = props.getProperty("driver");
            url = props.getProperty("url");
            username = props.getProperty("username");
            password = props.getProperty("password");
            LOGGER.error("zskxlog static~~~  driver=="+driver+"url=="+url+"username=="+username+"password=="+password);
        } catch (Exception e) {
            LOGGER.error("zskxlog ExamJDBCUtil error!!!"+e);
        }
    }

    public static Connection getConn() {

        Connection conn = null;

        try {
            LOGGER.error("zskxlog driver=="+driver+"url=="+url+"username=="+username+"password=="+password);
            Class.forName(driver);
            conn = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            LOGGER.error("zskxlog ExamJDBCUtil error!!!"+e);
        }

        return conn;
    }

    public static void closeConn(Connection conn) {

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void closePreStat(PreparedStatement ps) {

        try {
            if (ps != null) {
                ps.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void closeResSet(ResultSet rs) {

        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

测试信息

public class DonghuaJDBC {

PreparedStatement ps = null;
        Connection con = null;
        ResultSet rs = null;
        
        List<Medical> list=new ArrayList<Medical>();
        String sql = "select * from DHC_PE_PEMVIEW";
        con = ExamHisJDBCUtils.getConn();
        
        ps = con.prepareStatement(sql.toString());
        ps.setString(1, checkupId);
        
        
        rs = ps.executeQuery();
        while (rs.next()) {
            System.out.println("--------------"+rs.getString("Exam_No"));
        }
}

 

以上是java信息,jdbc连接方式获取

jar地址:https://download.csdn.net/download/qq_37996327/11473240

 

posted @ 2019-09-10 08:53  叶知秋qw  阅读(3555)  评论(0编辑  收藏  举报