Package org.postgresql.util

Examples of org.postgresql.util.PSQLException


        {
            defaults = getDefaultProperties();
        }
        catch (IOException ioe)
        {
            throw new PSQLException(GT.tr("Error loading default settings from driverconfig.properties"),
                                    PSQLState.UNEXPECTED_ERROR, ioe);
        }

        // override defaults with provided properties
        Properties props = new Properties(defaults);
        for (Enumeration e = info.propertyNames(); e.hasMoreElements(); )
        {
            String propName = (String)e.nextElement();
            props.setProperty(propName, info.getProperty(propName));
        }

        // parse URL and add more properties
        if ((props = parseURL(url, props)) == null)
        {
            logger.debug("Error in url: " + url);
            return null;
        }
        try
        {
            logger.debug("Connecting with URL: " + url);

            // Enforce login timeout, if specified, by running the connection
            // attempt in a separate thread. If we hit the timeout without the
            // connection completing, we abandon the connection attempt in
            // the calling thread, but the separate thread will keep trying.
            // Eventually, the separate thread will either fail or complete
            // the connection; at that point we clean up the connection if
            // we managed to establish one after all. See ConnectThread for
            // more details.
            long timeout = timeout(props);
            if (timeout <= 0)
                return makeConnection(url, props);

            ConnectThread ct = new ConnectThread(url, props);
            new Thread(ct, "PostgreSQL JDBC driver connection thread").start();
            return ct.getResult(timeout);
        }
        catch (PSQLException ex1)
        {
            logger.debug("Connection error:", ex1);
            // re-throw the exception, otherwise it will be caught next, and a
            // org.postgresql.unusual error will be returned instead.
            throw ex1;
        }
        catch (java.security.AccessControlException ace)
        {
            throw new PSQLException(GT.tr("Your security policy has prevented the connection from being attempted.  You probably need to grant the connect java.net.SocketPermission to the database server host and port that you wish to connect to."), PSQLState.UNEXPECTED_ERROR, ace);
        }
        catch (Exception ex2)
        {
            logger.debug("Unexpected connection error:", ex2);
            throw new PSQLException(GT.tr("Something unusual has occured to cause the driver to fail. Please report this exception."),
                                    PSQLState.UNEXPECTED_ERROR, ex2);
        }
    }
View Full Code Here


     * @return PSQLException with a localized message giving the complete
     *  description of the unimplemeted function
     */
    public static SQLException notImplemented(Class callClass, String functionName)
    {
        return new PSQLException(GT.tr("Method {0} is not yet implemented.", callClass.getName() + "." + functionName),
                                 PSQLState.NOT_IMPLEMENTED);
    }
View Full Code Here

                    if (resultException != null) {
                        if (resultException instanceof SQLException) {
                            resultException.fillInStackTrace();
                            throw (SQLException)resultException;
                        } else {
                            throw new PSQLException(GT.tr("Something unusual has occured to cause the driver to fail. Please report this exception."),
                                                    PSQLState.UNEXPECTED_ERROR, resultException);
                        }
                    }
                   
                    long delay = expiry - System.currentTimeMillis();
                    if (delay <= 0) {
                        abandoned = true;
                        throw new PSQLException(GT.tr("Connection attempt timed out."),
                                                PSQLState.CONNECTION_UNABLE_TO_CONNECT);
                    }
                   
                    try {
                        wait(delay);
                    } catch (InterruptedException ie) {
                        abandoned = true;
                        throw new PSQLException(GT.tr("Interrupted while attempting to connect."),
                                                PSQLState.CONNECTION_UNABLE_TO_CONNECT);
                    }                                           
                }
            }
        }
View Full Code Here

        setLiteralParameter(index, "" + value, Oid.INT4);
    }

    public void setLiteralParameter(int index, String value, int oid) throws SQLException {
        if (index < 1 || index > paramValues.length)
            throw new PSQLException(GT.tr("The column index is out of range: {0}, number of columns: {1}.", new Object[]{new Integer(index), new Integer(paramValues.length)}), PSQLState.INVALID_PARAMETER_VALUE );

        paramValues[index - 1] = value;
    }
View Full Code Here

        setLiteralParameter(index, sbuf.toString(), oid);
    }

    public void setBytea(int index, byte[] data, int offset, int length) throws SQLException {
        if (index < 1 || index > paramValues.length)
            throw new PSQLException(GT.tr("The column index is out of range: {0}, number of columns: {1}.", new Object[]{new Integer(index), new Integer(paramValues.length)}), PSQLState.INVALID_PARAMETER_VALUE );

        paramValues[index - 1] = new StreamWrapper(data, offset, length);
    }
View Full Code Here

        paramValues[index - 1] = new StreamWrapper(data, offset, length);
    }

    public void setBytea(int index, final InputStream stream, final int length) throws SQLException {
        if (index < 1 || index > paramValues.length)
            throw new PSQLException(GT.tr("The column index is out of range: {0}, number of columns: {1}.", new Object[]{new Integer(index), new Integer(paramValues.length)}), PSQLState.INVALID_PARAMETER_VALUE );

        paramValues[index - 1] = new StreamWrapper(stream, length);
    }
View Full Code Here

        paramValues[index - 1] = new StreamWrapper(stream, length);
    }

    public void setNull(int index, int oid) throws SQLException {
        if (index < 1 || index > paramValues.length)
            throw new PSQLException(GT.tr("The column index is out of range: {0}, number of columns: {1}.", new Object[]{new Integer(index), new Integer(paramValues.length)}), PSQLState.INVALID_PARAMETER_VALUE );

        paramValues[index - 1] = NULL_OBJECT;
    }
View Full Code Here

    void checkAllParametersSet() throws SQLException {
        for (int i = 0; i < paramValues.length; i++)
        {
            if (paramValues[i] == null)
                throw new PSQLException(GT.tr("No value specified for parameter {0}.", new Integer(i + 1)), PSQLState.INVALID_PARAMETER_VALUE);
        }
    }
View Full Code Here

            break;
        case ResultSet.HOLD_CURSORS_OVER_COMMIT:
            rsHoldability = holdability;
            break;
        default:
            throw new PSQLException(GT.tr("Unknown ResultSet holdability setting: {0}.", new Integer(holdability)),
                                    PSQLState.INVALID_PARAMETER_VALUE);
        }
    }
View Full Code Here

     * @since 1.4
     */
    public Savepoint setSavepoint() throws SQLException
    {
        if (!haveMinimumServerVersion("8.0"))
            throw new PSQLException(GT.tr("Server versions prior to 8.0 do not support savepoints."), PSQLState.NOT_IMPLEMENTED);
        if (getAutoCommit())
            throw new PSQLException(GT.tr("Cannot establish a savepoint in auto-commit mode."),
                                    PSQLState.NO_ACTIVE_SQL_TRANSACTION);

        PSQLSavepoint savepoint = new PSQLSavepoint(savepointId++);

        // Note we can't use execSQLUpdate because we don't want
View Full Code Here

TOP

Related Classes of org.postgresql.util.PSQLException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.