Package java.sql

Examples of java.sql.SQLException


     * @param option the unsupported option
     * @return this method never returns normally
     */
    protected SQLException throwUnsupportedOption(String option) throws SQLException {
        showUsage();
        throw new SQLException("Unsupported option: " + option);
    }
View Full Code Here


                batchParameters = New.arrayList();
            }
            int size = batchParameters.size();
            int[] result = new int[size];
            boolean error = false;
            SQLException next = null;
            checkClosedForWrite();
            try {
                for (int i = 0; i < size; i++) {
                    Value[] set = batchParameters.get(i);
                    ArrayList<? extends ParameterInterface> parameters = command.getParameters();
                    for (int j = 0; j < set.length; j++) {
                        Value value = set[j];
                        ParameterInterface param = parameters.get(j);
                        param.setValue(value, false);
                    }
                    try {
                        result[i] = executeUpdateInternal();
                    } catch (Exception re) {
                        SQLException e = logAndConvert(re);
                        if (next == null) {
                            next = e;
                        } else {
                            e.setNextException(next);
                            next = e;
                        }
                        result[i] = Statement.EXECUTE_FAILED;
                        error = true;
                    }
View Full Code Here

                throwUnsupportedOption(arg);
            }
        }
        if ((encryptPassword == null && decryptPassword == null) || cipher == null) {
            showUsage();
            throw new SQLException("Encryption or decryption password not set, or cipher not set");
        }
        try {
            process(dir, db, cipher, decryptPassword, encryptPassword, quiet);
        } catch (Exception e) {
            throw DbException.toSQLException(e);
View Full Code Here

        dir = FileLister.getDir(dir);
        ChangeFileEncryption change = new ChangeFileEncryption();
        if (encryptPassword != null) {
            for (char c : encryptPassword) {
                if (c == ' ') {
                    throw new SQLException("The file password may not contain spaces");
                }
            }
        }
        change.out = out;
        change.directory = dir;
View Full Code Here

  public static <T, ID> MappedUpdateId<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo)
      throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot update-id in " + tableInfo.getDataClass()
          + " because it doesn't have an id field");
    }
    StringBuilder sb = new StringBuilder(64);
    appendTableName(databaseType, sb, "UPDATE ", tableInfo.getTableName());
    sb.append("SET ");
View Full Code Here

  public static <T, ID> MappedDelete<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo)
      throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot delete from " + tableInfo.getDataClass()
          + " because it doesn't have an id field");
    }
    StringBuilder sb = new StringBuilder(64);
    appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName());
    appendWhereId(databaseType, idField, sb, null);
View Full Code Here

   */
  private static <T, ID> MappedDeleteCollection<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo,
      int dataSize) throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot delete " + tableInfo.getDataClass()
          + " because it doesn't have an id field defined");
    }
    StringBuilder sb = new StringBuilder(128);
    appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName());
    FieldType[] argFieldTypes = new FieldType[dataSize];
View Full Code Here

            break;
          }
        }
      }
      if (daoConstructor == null) {
        throw new SQLException("Could not find public constructor with ConnectionSource parameter in class "
            + daoClass);
      }
      try {
        dao = (Dao<?, ?>) daoConstructor.newInstance(arguments);
      } catch (Exception e) {
View Full Code Here

              e.getTargetException());
        } catch (Exception e) {
          throw SqlExceptionUtil.create("Could not run getSingleton method on class " + persisterClass, e);
        }
        if (result == null) {
          throw new SQLException("Static getSingleton method should not return null on class "
              + persisterClass);
        }
        try {
          dataPersister = (DataPersister) result;
        } catch (Exception e) {
          throw new SQLException(
              "Could not cast result of static getSingleton method to DataPersister from class "
                  + persisterClass);
        }
      }
    } else {
      dataPersister = fieldConfig.getDataPersister();
      if (!dataPersister.isValidForField(field)) {
        throw new IllegalArgumentException("Field class " + clazz + " for field " + this
            + " is not valid for data persister " + dataPersister);
      }
    }
    String defaultFieldName = field.getName();
    if (fieldConfig.isForeign() || fieldConfig.isForeignAutoRefresh()) {
      if (dataPersister != null && dataPersister.isPrimitive()) {
        throw new IllegalArgumentException("Field " + this + " is a primitive class " + clazz
            + " but marked as foreign");
      }
      defaultFieldName = defaultFieldName + FOREIGN_ID_FIELD_SUFFIX;
    } else if (fieldConfig.isForeignCollection()) {
      if (clazz != Collection.class && !ForeignCollection.class.isAssignableFrom(clazz)) {
        throw new SQLException("Field class for '" + field.getName() + "' must be of class "
            + ForeignCollection.class.getSimpleName() + " or Collection.");
      }
      Type type = field.getGenericType();
      if (!(type instanceof ParameterizedType)) {
        throw new SQLException("Field class for '" + field.getName() + "' must be a parameterized Collection.");
      }
      Type[] genericArguments = ((ParameterizedType) type).getActualTypeArguments();
      if (genericArguments.length == 0) {
        // i doubt this will ever be reached
        throw new SQLException("Field class for '" + field.getName()
            + "' must be a parameterized Collection with at least 1 type.");
      }
    } else if (dataPersister == null && (!fieldConfig.isForeignCollection())) {
      if (byte[].class.isAssignableFrom(clazz)) {
        throw new SQLException("ORMLite can't store unknown class " + clazz + " for field '" + field.getName()
            + "'. byte[] fields must specify dataType=DataType.BYTE_ARRAY or SERIALIZABLE");
      } else if (Serializable.class.isAssignableFrom(clazz)) {
        throw new SQLException("ORMLite can't store unknown class " + clazz + " for field '" + field.getName()
            + "'. Serializable fields must specify dataType=DataType.SERIALIZABLE");
      } else {
        throw new IllegalArgumentException("ORMLite does not know how to store field class " + clazz
            + " for field " + this);
      }
View Full Code Here

      }
      foreignFieldType = null;
      mappedQueryForId = null;
    } else if (fieldConfig.isForeignCollection()) {
      if (clazz != Collection.class && !ForeignCollection.class.isAssignableFrom(clazz)) {
        throw new SQLException("Field class for '" + field.getName() + "' must be of class "
            + ForeignCollection.class.getSimpleName() + " or Collection.");
      }
      Type type = field.getGenericType();
      if (!(type instanceof ParameterizedType)) {
        throw new SQLException("Field class for '" + field.getName() + "' must be a parameterized Collection.");
      }
      Type[] genericArguments = ((ParameterizedType) type).getActualTypeArguments();
      if (genericArguments.length == 0) {
        // i doubt this will ever be reached
        throw new SQLException("Field class for '" + field.getName()
            + "' must be a parameterized Collection with at least 1 type.");
      }
      clazz = (Class<?>) genericArguments[0];
      DatabaseTableConfig<?> tableConfig = fieldConfig.getForeignTableConfig();
      Dao<Object, Object> foundDao;
      if (tableConfig == null) {
        @SuppressWarnings("unchecked")
        Dao<Object, Object> castDao = (Dao<Object, Object>) DaoManager.createDao(connectionSource, clazz);
        foundDao = castDao;
      } else {
        @SuppressWarnings("unchecked")
        Dao<Object, Object> castDao = (Dao<Object, Object>) DaoManager.createDao(connectionSource, tableConfig);
        foundDao = castDao;
      }
      FieldType findForeignFieldType = null;
      for (FieldType fieldType : ((BaseDaoImpl<?, ?>) foundDao).getTableInfo().getFieldTypes()) {
        if (fieldType.getFieldType() == parentClass) {
          findForeignFieldType = fieldType;
          break;
        }
      }
      if (findForeignFieldType == null) {
        throw new SQLException("Foreign collection object " + clazz + " for field '" + field.getName()
            + "' does not contain a foreign field of class " + parentClass);
      }
      if (!findForeignFieldType.fieldConfig.isForeign()
          && !findForeignFieldType.fieldConfig.isForeignAutoRefresh()) {
        // this may never be reached
        throw new SQLException("Foreign collection object " + clazz + " for field '" + field.getName()
            + "' contains a field of class " + parentClass + " but it's not foreign");
      }
      foreignDao = foundDao;
      foreignFieldType = findForeignFieldType;
      foreignIdField = null;
View Full Code Here

TOP

Related Classes of java.sql.SQLException

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.