Example usage for java.sql Types VARCHAR

List of usage examples for java.sql Types VARCHAR

Introduction

In this page you can find the example usage for java.sql Types VARCHAR.

Prototype

int VARCHAR

To view the source code for java.sql Types VARCHAR.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARCHAR.

Usage

From source file:com.mirth.connect.donkey.model.channel.MetaDataColumnType.java

public static MetaDataColumnType fromSqlType(int sqlType) {
    switch (sqlType) {
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
    case Types.CLOB:
    case Types.NCLOB:
        return STRING;

    case Types.BIGINT:
    case Types.INTEGER:
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
        return NUMBER;

    case Types.BOOLEAN:
    case Types.BIT:
    case Types.CHAR:
        return BOOLEAN;

    case Types.TIMESTAMP:
    case Types.TIME:
    case Types.DATE:
        return TIMESTAMP;
    }// w  ww .  j  av a  2  s .  c  om

    return null;
}

From source file:com.cloudera.sqoop.hive.HiveTypes.java

/**
 * Given JDBC SQL types coming from another database, what is the best
 * mapping to a Hive-specific type?/*  ww  w. j a  v  a 2s  . co  m*/
 */
public static String toHiveType(int sqlType) {
    if (sqlType == Types.INTEGER) {
        return "INT";
    } else if (sqlType == Types.VARCHAR) {
        return "STRING";
    } else if (sqlType == Types.CHAR) {
        return "STRING";
    } else if (sqlType == Types.LONGVARCHAR) {
        return "STRING";
    } else if (sqlType == Types.NUMERIC) {
        // Per suggestion on hive-user, this is converted to DOUBLE for now.
        return "DOUBLE";
    } else if (sqlType == Types.DECIMAL) {
        // Per suggestion on hive-user, this is converted to DOUBLE for now.
        return "DOUBLE";
    } else if (sqlType == Types.BIT) {
        return "BOOLEAN";
    } else if (sqlType == Types.BOOLEAN) {
        return "BOOLEAN";
    } else if (sqlType == Types.TINYINT) {
        return "TINYINT";
    } else if (sqlType == Types.SMALLINT) {
        return "INT";
    } else if (sqlType == Types.BIGINT) {
        return "BIGINT";
    } else if (sqlType == Types.REAL) {
        return "DOUBLE";
    } else if (sqlType == Types.FLOAT) {
        return "DOUBLE";
    } else if (sqlType == Types.DOUBLE) {
        return "DOUBLE";
    } else if (sqlType == Types.DATE) {
        // unfortunate type coercion
        return "STRING";
    } else if (sqlType == Types.TIME) {
        // unfortunate type coercion
        return "STRING";
    } else if (sqlType == Types.TIMESTAMP) {
        // unfortunate type coercion
        return "STRING";
    } else if (sqlType == Types.CLOB) {
        return "STRING";
    } else {
        // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT,
        // BLOB, ARRAY, STRUCT, REF, JAVA_OBJECT.
        return null;
    }
}

From source file:Main.java

/**
 * Gets the name of the type to be used with the internal dbms
 * //from  w  w w .  java 2s . c o m
 * @param type
 *            java.sql.Types constant
 * 
 * @return String
 * 
 * @throws RuntimeException
 *             If the Type is not recognized
 */
public static String getTypeString(int type) {
    switch (type) {
    case Types.BIGINT:
        return "BIGINT";

    case Types.BIT:
    case Types.BOOLEAN:
        return "BOOLEAN";

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return "VARCHAR";

    case Types.DATE:
        return "DATE";

    case Types.DECIMAL:
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
        return "DOUBLE";

    case Types.INTEGER:
        return "INTEGER";

    case Types.SMALLINT:
        return "SHORT";

    case Types.TINYINT:
        return "BYTE";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return "BINARY";

    case Types.TIMESTAMP:
        return "TIMESTAMP";

    case Types.TIME:
        return "TIME";

    default:
        throw new RuntimeException("Cannot edit the type: " + type);
    }
}

From source file:orz.neptune.prospring3.ch8.UpdateContact.java

public UpdateContact(DataSource dataSource) {
    super(dataSource, SQL_UPDATE_CONTACT);
    super.declareParameter(new SqlParameter("first_name", Types.VARCHAR));
    super.declareParameter(new SqlParameter("last_name", Types.VARCHAR));
    super.declareParameter(new SqlParameter("birth_date", Types.DATE));
    super.declareParameter(new SqlParameter("id", Types.INTEGER));
}

From source file:orz.neptune.prospring3.ch8.InsertContact.java

public InsertContact(DataSource dataSource) {
    super(dataSource, SQL_INSERT_CONTACT);
    super.declareParameter(new SqlParameter("first_name", Types.VARCHAR));
    super.declareParameter(new SqlParameter("last_name", Types.VARCHAR));
    super.declareParameter(new SqlParameter("birth_date", Types.DATE));
    super.setGeneratedKeysColumnNames(new String[] { "id" });
    super.setReturnGeneratedKeys(true);
}

From source file:com.home.ln_spring.ch8.dao.jdbc.annotation.InsertContact.java

public InsertContact(DataSource dataSource) {
    super(dataSource, SQL_INSERT_CONTACT);
    super.declareParameter(new SqlParameter("first_name", Types.VARCHAR));
    super.declareParameter(new SqlParameter("last_name", Types.VARCHAR));
    super.declareParameter(new SqlParameter("birth_date", Types.DATE));
    super.setGeneratedKeysColumnNames(new String[] { "contact_id" });
    super.setReturnGeneratedKeys(true);
}

From source file:Main.java

public static String getCloverTypeFromJdbcType(int jdbcDataType) {
    switch (jdbcDataType) {
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return "date";
    case Types.ARRAY:
    case Types.BINARY:
    case Types.DATALINK:
    case Types.BLOB:
    case Types.DISTINCT:
    case Types.JAVA_OBJECT:
    case Types.NULL:
    case Types.OTHER:
    case Types.REF:
    case Types.STRUCT:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        System.out.println("Outputting cbyte for Type: " + jdbcDataType);
        return "cbyte";
    case Types.BIT:
    case Types.BOOLEAN:
        return "boolean";
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
        return "numeric";
    case Types.INTEGER:
    case Types.SMALLINT:
        return "integer";
    case Types.BIGINT:
        return "long";
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.CLOB:
    case Types.LONGVARCHAR:
        return "string";
    }/*from   www  .  ja va2  s  . c  om*/
    System.out.println("Outputting string for unknown Type: " + jdbcDataType);
    return "string";
}

From source file:com.home.ln_spring.ch8.dao.jdbc.annotation.UpdateContact.java

public UpdateContact(DataSource dataSource) {
    super(dataSource, SQL_UPDATE_CONTACT);
    super.declareParameter(new SqlParameter("first_name", Types.VARCHAR));
    super.declareParameter(new SqlParameter("last_name", Types.VARCHAR));
    super.declareParameter(new SqlParameter("birth_date", Types.DATE));
    super.declareParameter(new SqlParameter("contact_id", Types.INTEGER));
}

From source file:com.home.ln_spring.ch8.dao.jdbc.annotation.SelectContactByFirstName.java

public SelectContactByFirstName(DataSource dataSource) {
    super(dataSource, SQL_FIND_BY_FIRST_NAME);
    super.declareParameter(new SqlParameter("first_name", Types.VARCHAR));
}

From source file:Spring.Repaso02.ClienteDAO.java

@Override
public boolean alta(Cliente c) {
    String inserQuery = "insert into TClientes (idCliente, Pass, Nombre, Apellidos, Telefono, Email) values (?, ?, ?, ?, ?, ?) ";
    Object[] params = new Object[] { c.getIdCliente(), c.getPassword(), c.getNombre(), c.getApellidos(),
            c.getTelefono(), c.getEmail() };
    int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
            Types.VARCHAR };//from  www.  j a v  a 2s  .  c  om
    jdbcTemplate.update(inserQuery, params, types);
    return true;
}