我的查询是
select* from "Table"."SampleDB";
我的Java代码是
String dbURL = "jdbc:postgresql://localhost:5433/Table.SampleDB";
String user = "postgres";
String pass = "pass";
conn = DriverManager.getConnection(dbURL, user, pass);
我无法连接到数据库。如何调用" schema.TableName"在servlet getConnection中。请帮我解决这个问题。
答案 0 :(得分:-2)
尝试使用它:
String dbName=DB_NAME;//The name of DB
String user = "postgres";
String pass = "pass";
String dbURL = "jdbc:postgresql://localhost:5433/"+ dbName;
conn = DriverManager.getConnection(dbURL, user, pass);
或者这个:
Class.forName("org.postgresql.Driver");
Connection connection = null;
String dbName=DB_NAME;//The name of DB
String user = "postgres";
String pass = "pass";
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost:5433/"+dbName,user,pass);
希望这有助于。