与schema.tableName的数据库连接

时间:2016-01-26 17:04:57

标签: java postgresql jdbc

我的查询是

 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中。请帮我解决这个问题。

1 个答案:

答案 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);

希望这有助于。