Codota Logo
PgConnection
Code IndexAdd Codota to your IDE (free)

How to use
PgConnection
in
org.postgresql.jdbc

Best Java code snippets using org.postgresql.jdbc.PgConnection (Showing top 20 results out of 315)

  • Common ways to obtain PgConnection
private void myMethod () {
PgConnection p =
  • Codota IconConnection connection;connection.unwrap(PgConnection.class)
  • Smart code suggestions by Codota
}
origin: org.postgresql/postgresql

/**
 * <p>Overrides finalize(). If called, it closes the connection.</p>
 *
 * <p>This was done at the request of <a href="mailto:rachel@enlarion.demon.co.uk">Rachel
 * Greenham</a> who hit a problem where multiple clients didn't close the connection, and once a
 * fortnight enough clients were open to kill the postgres server.</p>
 */
protected void finalize() throws Throwable {
 try {
  if (openStackTrace != null) {
   LOGGER.log(Level.WARNING, GT.tr("Finalizing a Connection that was never closed:"), openStackTrace);
  }
  close();
 } finally {
  super.finalize();
 }
}
origin: org.postgresql/postgresql

@Override
public int getDatabaseMajorVersion() throws SQLException {
 return connection.getServerMajorVersion();
}
origin: org.postgresql/postgresql

@Override
public void addDataType(String type, String name) {
 try {
  addDataType(type, Class.forName(name).asSubclass(PGobject.class));
 } catch (Exception e) {
  throw new RuntimeException("Cannot register new type: " + e);
 }
}
origin: org.postgresql/postgresql

@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency)
  throws SQLException {
 checkClosed();
 return createStatement(resultSetType, resultSetConcurrency, getHoldability());
}
origin: org.postgresql/postgresql

public String getSchema() throws SQLException {
 checkClosed();
 Statement stmt = createStatement();
 try {
  ResultSet rs = stmt.executeQuery("select current_schema()");
  try {
   if (!rs.next()) {
    return null; // Is it ever possible?
   }
   return rs.getString(1);
  } finally {
   rs.close();
  }
 } finally {
  stmt.close();
 }
}
origin: org.postgresql/postgresql

public void setSchema(String schema) throws SQLException {
 checkClosed();
 Statement stmt = createStatement();
 try {
  if (schema == null) {
   stmt.executeUpdate("SET SESSION search_path TO DEFAULT");
  } else {
   StringBuilder sb = new StringBuilder();
   sb.append("SET SESSION search_path TO '");
   Utils.escapeLiteral(sb, schema, getStandardConformingStrings());
   sb.append("'");
   stmt.executeUpdate(sb.toString());
   LOGGER.log(Level.FINE, "  setSchema = {0}", schema);
  }
 } finally {
  stmt.close();
 }
}
origin: debezium/debezium

@Test
@FixFor("DBZ-934")
public void temporaryReplicationSlotsShouldGetDroppedAutomatically() throws Exception {
  try(ReplicationConnection replicationConnection = TestHelper.createForReplication("test", true)) {
    PgConnection pgConnection = getUnderlyingConnection(replicationConnection);
    // temporary replication slots are not supported by Postgres < 10
    if (pgConnection.getServerMajorVersion() < 10) {
      return;
    }
    // simulate ungraceful shutdown by closing underlying database connection
    pgConnection.close();
    try (PostgresConnection connection = TestHelper.create()) {
      assertFalse("postgres did not drop replication slot", connection.dropReplicationSlot("test"));
    }
  }
}
origin: org.postgresql/postgresql

  + " ORDER BY a.attnum ";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
 int typeOid = (int) rs.getLong("atttypid");
 int typeMod = rs.getInt("atttypmod");
 int decimalDigits = connection.getTypeInfo().getScale(typeOid, typeMod);
 int columnSize = connection.getTypeInfo().getPrecision(typeOid, typeMod);
 if (columnSize == 0) {
  columnSize = connection.getTypeInfo().getDisplaySize(typeOid, typeMod);
 tuple[0] = connection.encodeString(Integer.toString(scope));
 tuple[1] = rs.getBytes("attname");
 tuple[2] =
   connection.encodeString(Integer.toString(connection.getTypeInfo().getSQLType(typeOid)));
 tuple[3] = connection.encodeString(connection.getTypeInfo().getPGType(typeOid));
 tuple[4] = connection.encodeString(Integer.toString(columnSize));
 tuple[5] = null; // unused
 tuple[6] = connection.encodeString(Integer.toString(decimalDigits));
 tuple[7] =
   connection.encodeString(Integer.toString(java.sql.DatabaseMetaData.bestRowNotPseudo));
 v.add(tuple);
origin: org.postgresql/postgresql

@Override
public Savepoint setSavepoint(String name) throws SQLException {
 checkClosed();
 if (getAutoCommit()) {
  throw new PSQLException(GT.tr("Cannot establish a savepoint in auto-commit mode."),
    PSQLState.NO_ACTIVE_SQL_TRANSACTION);
 }
 PSQLSavepoint savepoint = new PSQLSavepoint(name);
 // Note we can't use execSQLUpdate because we don't want
 // to suppress BEGIN.
 Statement stmt = createStatement();
 stmt.executeUpdate("SAVEPOINT " + savepoint.getPGName());
 stmt.close();
 return savepoint;
}
origin: org.postgresql/postgresql

@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
 try {
  checkClosed();
 } catch (final SQLException cause) {
  Map<String, ClientInfoStatus> failures = new HashMap<String, ClientInfoStatus>();
 if (haveMinimumServerVersion(ServerVersion.v9_0) && "ApplicationName".equals(name)) {
  if (value == null) {
   value = "";
   Utils.escapeLiteral(sql, value, getStandardConformingStrings());
   sql.append("'");
   execSQLUpdate(sql.toString());
  } catch (SQLException sqle) {
   Map<String, ClientInfoStatus> failures = new HashMap<String, ClientInfoStatus>();
 addWarning(new SQLWarning(GT.tr("ClientInfo property not supported."),
   PSQLState.NOT_IMPLEMENTED.getState()));
origin: org.postgresql/postgresql

if (connection.haveMinimumServerVersion(ServerVersion.v8_4)) {
 sql = "SELECT * FROM (";
} else {
if (connection.haveMinimumServerVersion(ServerVersion.v8_4)) {
 sql += "row_number() OVER (PARTITION BY a.attrelid ORDER BY a.attnum) AS attnum, ";
} else {
if (connection.haveMinimumServerVersion(ServerVersion.v10)) {
 sql += "nullif(a.attidentity, '') as attidentity,";
} else {
if (connection.haveMinimumServerVersion(ServerVersion.v8_4)) {
 sql += ") c WHERE true ";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
  sqlType = Types.VARCHAR;
 } else {
  sqlType = connection.getTypeInfo().getSQLType(typeOid);
 tuple[4] = connection.encodeString(Integer.toString(sqlType));
 String pgType = connection.getTypeInfo().getPGType(typeOid);
 tuple[5] = connection.encodeString(pgType); // Type name
 tuple[7] = null; // Buffer length
  if (pgType.equals("int4")) {
origin: org.postgresql/postgresql

   PSQLState.INVALID_PARAMETER_VALUE);
if (isClosed()) {
 return false;
  Statement statement = createStatement();
  statement.execute("IDENTIFY_SYSTEM");
  statement.close();
 } else {
  if (checkConnectionQuery == null) {
   checkConnectionQuery = prepareStatement("");
origin: jerolba/jfleet

private CopyManager getCopyManager(Connection conn) throws SQLException {
  PgConnection unwrapped = conn.unwrap(PgConnection.class);
  return unwrapped.getCopyAPI();
}
origin: org.postgresql/postgresql

connection.checkClosed();
if (keywords == null) {
 if (connection.haveMinimumServerVersion(ServerVersion.v9_0)) {
  ResultSet rs = null;
  try {
   stmt = connection.createStatement();
   rs = stmt.executeQuery(sql);
   if (!rs.next()) {
origin: org.postgresql/postgresql

   + (connection.haveMinimumServerVersion(ServerVersion.v8_4) ? "a.attacl, " : "")
   + " a.attname "
   + " FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c, "
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
 if (connection.haveMinimumServerVersion(ServerVersion.v8_4)) {
  String acl = rs.getString("attacl");
  Map<String, Map<String, List<String[]>>> relPermissions = parseACL(acl, owner);
 Arrays.sort(permNames);
 for (String permName : permNames) {
  byte[] privilege = connection.encodeString(permName);
  Map<String, List<String[]>> grantees = permissions.get(permName);
  for (Map.Entry<String, List<String[]>> userToGrantable : grantees.entrySet()) {
    tuple[2] = tableName;
    tuple[3] = column;
    tuple[4] = connection.encodeString(grants[0]);
    tuple[5] = connection.encodeString(grantee);
    tuple[6] = privilege;
    tuple[7] = connection.encodeString(grantable);
    v.add(tuple);
origin: org.postgresql/postgresql

@Override
public void execSQLUpdate(String s) throws SQLException {
 BaseStatement stmt = (BaseStatement) createStatement();
 if (stmt.executeWithFlags(s, QueryExecutor.QUERY_NO_METADATA | QueryExecutor.QUERY_NO_RESULTS
   | QueryExecutor.QUERY_SUPPRESS_BEGIN)) {
  throw new PSQLException(GT.tr("A result was returned when none was expected."),
    PSQLState.TOO_MANY_RESULTS);
 }
 // Transfer warnings to the connection, since the user never
 // has a chance to see the statement itself.
 SQLWarning warnings = stmt.getWarnings();
 if (warnings != null) {
  addWarning(warnings);
 }
 stmt.close();
}
origin: debezium/debezium

try (Statement stmt = pgConnection().createStatement()) {
  stmt.execute(String.format(
      "CREATE_REPLICATION_SLOT %s TEMPORARY LOGICAL %s",
pgConnection().getReplicationAPI()
  .createReplicationSlot()
  .logical()
origin: org.postgresql/postgresql

@Override
public Statement createStatement() throws SQLException {
 // We now follow the spec and default to TYPE_FORWARD_ONLY.
 return createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
}
origin: debezium/debezium

private Charset determineDatabaseCharset() {
  try {
    return Charset.forName(((PgConnection) connection()).getEncoding().name());
  }
  catch (SQLException e) {
    throw new RuntimeException("Couldn't obtain encoding for database " + database(), e);
  }
}
origin: org.postgresql/postgresql

Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
 Arrays.sort(permNames);
 for (String permName : permNames) {
  byte[] privilege = connection.encodeString(permName);
  Map<String, List<String[]>> grantees = permissions.get(permName);
  for (Map.Entry<String, List<String[]>> userToGrantable : grantees.entrySet()) {
    tuple[1] = schema;
    tuple[2] = table;
    tuple[3] = connection.encodeString(grantor);
    tuple[4] = connection.encodeString(granteeUser);
    tuple[5] = privilege;
    tuple[6] = connection.encodeString(grantable);
    v.add(tuple);
org.postgresql.jdbcPgConnection

Most used methods

  • close
    Note: even though Statement is automatically closed when it is garbage collected, it is better to cl
  • getServerMajorVersion
    Get server major version.
  • addDataType
  • createStatement
  • getCopyAPI
  • getEncoding
  • <init>
  • abort
  • addWarning
    This adds a warning to the warning chain.
  • appendArray
  • borrowCallableQuery
  • borrowQuery
  • borrowCallableQuery,
  • borrowQuery,
  • borrowReturningQuery,
  • checkClosed,
  • commit,
  • createQuery,
  • createTypeInfo,
  • encodeString,
  • escapeString,
  • execSQLQuery

Popular in Java

  • Making http post requests using okhttp
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • getContentResolver (Context)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Kernel (java.awt.image)
  • PrintWriter (java.io)
    Prints formatted representations of objects to a text-output stream. This class implements all of th
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now