private static void checkByte(int ch, int pos, int len) throws IOException { if ((ch & 0xc0) != 0x80) { throw new IOException( GT.tr("Illegal UTF-8 sequence: byte {0} of {1} byte sequence is not 10xxxxxx: {2}", pos, len, ch)); } }
public void handleCommandStatus(String status) throws PSQLException { if (status.startsWith("COPY")) { int i = status.lastIndexOf(' '); handledRowCount = i > 3 ? Long.parseLong(status.substring(i + 1)) : -1; } else { throw new PSQLException(GT.tr("CommandComplete expected COPY but got: " + status), PSQLState.COMMUNICATION_ERROR); } }
private static PSQLException cannotCastException(final String fromType, final String toType, final Exception cause) { return new PSQLException( GT.tr("Cannot convert an instance of {0} to type {1}", fromType, toType), PSQLState.INVALID_PARAMETER_TYPE, cause); }
public static double toDouble(String s) throws SQLException { if (s != null) { try { s = s.trim(); return Double.parseDouble(s); } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Bad value for type {0} : {1}", "double", s), PSQLState.NUMERIC_VALUE_OUT_OF_RANGE); } } return 0; // SQL NULL }
public String getSavepointName() throws SQLException { if (!_isValid) { throw new PSQLException(GT.tr("Cannot reference a savepoint after it has been released."), PSQLState.INVALID_SAVEPOINT_SPECIFICATION); } if (!_isNamed) { throw new PSQLException(GT.tr("Cannot retrieve the name of an unnamed savepoint."), PSQLState.WRONG_OBJECT_TYPE); } return _name; }
public java.sql.ResultSet executeQuery(String p_sql) throws SQLException { throw new PSQLException( GT.tr("Can''t use query methods that take a query string on a PreparedStatement."), PSQLState.WRONG_OBJECT_TYPE); }
public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException { if (type == ResultSet.class) { return type.cast(getObject(parameterIndex)); } throw new PSQLException(GT.tr("Unsupported type conversion to {1}.", type), PSQLState.INVALID_PARAMETER_VALUE); }
public void write(int b) throws IOException { checkClosed(); if (b < 0 || b > 255) { throw new IOException(GT.tr("Cannot write to copy a byte of value {0}", b)); } singleByteBuffer[0] = (byte) b; write(singleByteBuffer, 0, 1); }
public void setMaxFieldSize(int max) throws SQLException { checkClosed(); if (max < 0) { throw new PSQLException( GT.tr("The maximum field size must be a value greater than or equal to 0."), PSQLState.INVALID_PARAMETER_VALUE); } maxfieldSize = max; }
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { if (columnIndexes == null || columnIndexes.length == 0) { return executeUpdate(sql); } throw new PSQLException(GT.tr("Returning autogenerated keys by column index is not supported."), PSQLState.NOT_IMPLEMENTED); }
protected void checkClosed() throws SQLException { if (isClosed()) { throw new PSQLException(GT.tr("This connection has been closed."), PSQLState.CONNECTION_DOES_NOT_EXIST); } }
public void addBatch(String p_sql) throws SQLException { checkClosed(); throw new PSQLException( GT.tr("Can''t use query methods that take a query string on a PreparedStatement."), PSQLState.WRONG_OBJECT_TYPE); }
@Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { if (columnIndexes != null && columnIndexes.length == 0) { return prepareStatement(sql); } checkClosed(); throw new PSQLException(GT.tr("Returning autogenerated keys is not supported."), PSQLState.NOT_IMPLEMENTED); }
public void setProperty(String name, String value) throws SQLException { PGProperty pgProperty = PGProperty.forName(name); if (pgProperty != null) { setProperty(pgProperty, value); } else { throw new PSQLException(GT.tr("Unsupported property name: {0}", name), PSQLState.INVALID_PARAMETER_VALUE); } }
public boolean relative(int rows) throws SQLException { checkScrollable(); if (onInsertRow) { throw new PSQLException(GT.tr("Can''t use relative move methods while on the insert row."), PSQLState.INVALID_CURSOR_STATE); } // have to add 1 since absolute expects a 1-based index return absolute(current_row + 1 + rows); }
public synchronized void cancelRowUpdates() throws SQLException { checkClosed(); if (onInsertRow) { throw new PSQLException(GT.tr("Cannot call cancelRowUpdates() when on the insert row."), PSQLState.INVALID_CURSOR_STATE); } if (doingUpdates) { doingUpdates = false; clearRowBuffer(true); } }
public int findColumn(String columnName) throws SQLException { checkClosed(); int col = findColumnIndex(columnName); if (col == 0) { throw new PSQLException( GT.tr("The column name {0} was not found in this ResultSet.", columnName), PSQLState.UNDEFINED_COLUMN); } return col; }
@Override public byte[] encodeString(String str) throws SQLException { try { return getEncoding().encode(str); } catch (IOException ioe) { throw new PSQLException(GT.tr("Unable to translate data into the desired encoding."), PSQLState.DATA_ERROR, ioe); } }
public int getNetworkTimeout() throws SQLException { checkClosed(); try { return queryExecutor.getNetworkTimeout(); } catch (IOException ioe) { throw new PSQLException(GT.tr("Unable to get network timeout."), PSQLState.COMMUNICATION_ERROR, ioe); } }
@Override public void commit() throws SQLException { checkClosed(); if (autoCommit) { throw new PSQLException(GT.tr("Cannot commit when autoCommit is enabled."), PSQLState.NO_ACTIVE_SQL_TRANSACTION); } if (queryExecutor.getTransactionState() != TransactionState.IDLE) { executeTransactionCommand(commitQuery); } }