简体   繁体   English

JDBC使用密码连接但没有用户名吗?

[英]JDBC connect with password but no username?

I am trying to connect to a server (via JDBC) which requires a password, but a blank username. 我试图连接到服务器(通过JDBC),该服务器需要密码,但用户名空白。 When I try using an empty String ("") it causes an error: 当我尝试使用空字符串(“”)时,会导致错误:

java.sql.SQLException: invalid arguments in call java.sql.SQLException:调用中的无效参数

The code I am using worked to connect to another server (which requires username and password), so it is operable; 我正在使用的代码可以连接到另一台服务器(需要用户名和密码),因此它是可操作的; just not in this specific case (empty string username). 只是在这种情况下不可以(空字符串用户名)。 I also can access the connection for this specific server which requires no username via SQLDeveloper, so that's not offline or inaccessible. 我还可以通过SQLDeveloper访问此不需要用户名的特定服务器的连接,这样就不会脱机或无法访问。 In SQLDeveloper I can enter an empty username field without incident. 在SQLDeveloper中,我可以输入一个空的用户名字段而不会发生任何事件。

From what I've read one can connect with JDBC with username and password, or with neither. 从我所读的内容中,可以使用用户名和密码或不使用JDBC连接JDBC。 But I can't find a solution for a blank username. 但是我找不到空白用户名的解决方案。 There must be a hacky way around the problem. 解决该问题的方法一定很简单。

private Connection getConnection() throws SQLException
{
    OracleDataSource ds = new OracleDataSource();
    ds.setURL("jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid);
    System.out.println("attempting connection");
    connection = ds.getConnection(textFieldUsername.getText(), new String(passwordField.getPassword()));
    System.out.println("connection established");
    return connection;
}

Have you tried to connect through the DriverManager interface? 您是否尝试过通过DriverManager界面进行连接?

Connection conn = DriverManager.getConnection(url, props);

Where props doesn't have any entry for the username. 其中props没有用户名的任何条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM