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)+"\t"+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);
}
}

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-12-26
  • 2021-09-29
  • 2021-11-19
  • 2022-03-04
  • 2022-12-23
猜你喜欢
  • 2021-11-17
  • 2022-12-23
  • 2021-06-09
  • 2021-06-01
  • 2022-01-23
  • 2022-12-23
  • 2021-07-31
相关资源
相似解决方案