zoukankan      html  css  js  c++  java
  • 数据源加密-JDBC调用方式加密示例

    package test;

    import org.gjt.mm.mysql.Driver;

    import java.sql.*;
    import java.util.Properties;
    import java.util.logging.Logger;

    public class EncryptJDBC extends Driver{

    public static void main(String[] args) throws SQLException, ClassNotFoundException {

    Class.forName(EncryptJDBC.class.getName());
    DriverManager.registerDriver(new EncryptJDBC());
    Connection conn = DriverManager.getConnection("zpc:test1");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(" select * from datasource_group_info ");
    while(rs.next())
    {
    System.out.println(rs.getInt(1)+" "+rs.getString(2) +rs.getString("type"));
    }
    conn.close();
    }

    public static String getURLByKey(String key)
    {
    if("zpc:test1".equals(key))
    return "jdbc:mysql://10.27.89.6:3306/mydb";
    else
    return null;
    }

    public static void getPropertiesByKey(String key,Properties props)
    {
    props.setProperty("user", "zzz");
    props.setProperty("password", "ppp");
    }

    public CryptedJDBC() throws SQLException {
    }

    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
    return null;
    }

    @Override
    public boolean acceptsURL(String url) throws SQLException {
    if(url.startsWith("zpc:"))
    {
    return true;
    }
    return false;
    }

    @Override
    public Connection connect(String key, Properties info) throws SQLException {
    String realurl = getURLByKey(key);
    getPropertiesByKey(key, info);
    return super.connect(realurl, info);
    }
    }

  • 相关阅读:
    H.Playing games
    P4721 【模板】分治 FFT
    hdu5730 分治fft
    hdu6394Tree lct
    bzoj2763: [JLOI2011]飞行路线 最短路
    bzoj2154: Crash的数字表格 莫比乌斯反演
    bzoj3211: 花神游历各国 线段树
    溢流
    css控制继承
    “<textarea>”内的文字对齐
  • 原文地址:https://www.cnblogs.com/drawwindows/p/4884314.html
Copyright © 2011-2022 走看看