我有一个从数据库中读取主键的函数,由于某种原因,我无法读取正斜线。
host: jdbc:postgresql://databaseurl
dbname: databasename
dbuser: databaseuser
dbpass: databasepass
这是我的输入,这是我对该输入的功能
public static String pkDatabase(String host, String dbname, String dbuser, String dbpass, String table)
throws IOException, SQLException {
String url = host + "//" + dbname;
String user = dbuser;
String password = dbpass;
Connection conn = DriverManager.getConnection(url, user, password);
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs1 = meta.getTables(null, null, table, new String[] { table });
rs1 = meta.getPrimaryKeys(null, null, table);
ArrayList<String> arr = new ArrayList<String>();
while (rs1.next()) {
arr.add(rs1.getString(4));
}
String listString = "";
for (String s : arr) {
listString += s;
}
return listString;
}
这是我的输出
FATAL: database "/databasename" does not exist
我该如何解决?
您的问题在这一行
String url = host + "//" + dbname;
应该只有一个斜杠
String url = host + "/" + dbname;