jdbc:postgresql://192.168.1.23:12308/test?useUnicode=true&characterEncoding=gbk&allowEncodingChanges=true"
见官网:https://jdbc.postgresql.org/documentation/documentation.html
Connecting to the Database
With JDBC, a database is represented by a URL (Uniform Resource Locator). With PostgreSQL™, this takes one of the following forms:
- jdbc:postgresql:
database
- jdbc:postgresql://
host/database
- jdbc:postgresql://
host:port/database
The parameters have the following meanings:
-
host
The host name of the server. Defaults to
localhost
. To specify an IPv6 address your must enclose thehost
parameter with square brackets, for example:jdbc:postgresql://[::1]:5740/accounting
-
port
The port number the server is listening on. Defaults to the PostgreSQL™ standard port number (5432).
-
database
The database name.
To connect, you need to get a Connection
instance from JDBC. To do this, you use the DriverManager.getConnection()
method:
Connection db = DriverManager.getConnection(url, username, password)
;
Connection Parameters
In addition to the standard connection parameters the driver supports a number of additional properties which can be used to specify additional driver behaviour specific to PostgreSQL™. These properties may be specified in either the connection URL or an additional Properties
object parameter to DriverManager.getConnection
. The following examples illustrate the use of both methods to establish a SSL connection.
String url = "jdbc:postgresql://localhost/test";
Properties props = new Properties();
props.setProperty("user","fred");
props.setProperty("password","secret");
props.setProperty("ssl","true");
Connection conn = DriverManager.getConnection(url, props);
String url = "jdbc:postgresql://localhost/test?user=fred&password=secret&ssl=true";
Connection conn = DriverManager.getConnection(url);
-
user = String
The database user on whose behalf the connection is being made.
-
password = String
The database user's password.
-
ssl
Connect using SSL. The driver must have been compiled with SSL support. This property does not need a value associated with it. The mere presence of it specifies a SSL connection. However, for compatibility with future versions, the value &#