我在Windows上使用gephi 0.9.2
。我可以通过输入所有参数,包括File - Import Database - Edge List
连接到我的SQL Server(2016)。 gui中的用户名和密码(这意味着通过SQL Server身份验证进行连接)。我想使用集成安全性(“ Windows身份验证”)连接到数据库。我找不到输入连接字符串或以任何其他方式提供该信息的方法。
gephi 0.9.2中有什么方法可以直接定义与SQL Server的连接字符串?
这将完美地完成工作:
jdbc:sqlserver://server\instance;databaseName=DBName;integratedSecurity=true;
我只能找到漫游配置文件中的一个二进制文件“ EdgeListDatabase”。但这似乎只保留在gui中输入的数据。
答案 0 :(得分:1)
以下是建立连接的方式(除了通过“边缘列表”以外没有其他方法):
gephi/io/importer/plugin/database/ImporterEdgeList.java
private void importData() throws Exception {
//Connect database
String url = SQLUtils.getUrl(database.getSQLDriver(), database.getHost(), database.getPort(), database.getDBName());
try {
report.log("Try to connect at " + url);
connection = database.getSQLDriver().getConnection(url, database.getUsername(), database.getPasswd());
report.log("Database connection established");
}
这是getUrl从边缘列表中传递的字段中形成连接字符串的方式: gephi/io/database/drivers/SQLUtils.java
public static String getUrl(SQLDriver driver, String host, int port, String dbname) {
String res = "jdbc:";
res += driver != null ? driver.getPrefix() : "";
res += "://";
res += host != null ? host : "";
res += ":";
res += port != 0 ? port : "";
res += dbname != null ? "/" + dbname : "";
return res;
}
这是在SQLServerDriver中建立最终连接的方法: gephi/modules/DBDrivers/src/main/java/org/gephi/io/database/drivers/SQLServerDriver.java
public Connection getConnection(String connectionUrl, String username, String passwd) throws SQLException {
//Bug #745414
if (!connectionUrl.contains(";databaseName=")) {
String dbname = connectionUrl.substring(connectionUrl.lastIndexOf('/') + 1);
String url = connectionUrl.substring(0, connectionUrl.lastIndexOf('/'));
connectionUrl = url + ";databaseName=" + dbname;
}
return DriverManager.getConnection(connectionUrl, username, passwd);
}
public static Connection getConnection(String url, String user, String password)
如果将主机设置为:您可以在主机字段上进行注入
server\instance;integratedSecurity=true;authenticationScheme=javakerberos;password=
如果您将插入的res += ":";
用作 password =:,则会绕过语法错误。
照常设置dbName,将端口留空,并设置虚拟的用户名和密码。
现在,您必须希望驱动程序不会推翻Windows身份验证,因为您使用凭据调用了getConnection。
如果这不起作用,您唯一的方法是更改ImporterEdgeList.java插件的源以调用getConnection(String url),如果冒号绕过不起作用,则基于database.getHost()手动伪造URL。不行。
类似的东西:
private void importData() throws Exception {
//Connect database
String url = "jdbc:";
url += driver != null ? database.getSQLDriver().getPrefix() : "sqlserver";
url += "://";
url += database.getHost();
try {
report.log("Try to connect at " + url);
connection = database.getSQLDriver().getConnection(url);
report.log("Database connection established");
}
通过此技巧,您可以在主机变量上指定其余的连接字符串