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:Spring.Repaso01.ClienteDAO.java

@Override
public void modificacion(Cliente c) {
    String modQuery = "update Cliente set Nombre = ?, Ape1 = ?, Ape2 = ?, Saldo = ? where idCliente = ?";
    Object[] params = new Object[] { c.getNombre(), c.getApe1(), c.getApe2(), c.getSaldo(), c.getIdCliente() };
    int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.DECIMAL, Types.INTEGER };
    jdbcTemplate.update(modQuery, params, types);
}

From source file:net.sourceforge.vulcan.spring.jdbc.ChangeSetInserter.java

public ChangeSetInserter(DataSource dataSource) {
    setDataSource(dataSource);/*from w  w w . ja va  2  s.c  o  m*/
    setSql("insert into change_sets "
            + "(build_id, change_set_id, message, revision_label, commit_timestamp, author, author_email) "
            + "values (?, ?, ?, ?, ?, ?, ?)");

    declareParameter(new SqlParameter(Types.NUMERIC));
    declareParameter(new SqlParameter(Types.NUMERIC));
    declareParameter(new SqlParameter(Types.VARCHAR));
    declareParameter(new SqlParameter(Types.VARCHAR));
    declareParameter(new SqlParameter(Types.TIMESTAMP));
    declareParameter(new SqlParameter(Types.VARCHAR));
    declareParameter(new SqlParameter(Types.VARCHAR));

    compile();

    modifiedPathInserter = new ModifiedPathInserter(dataSource);
}

From source file:edu.wisc.bnsemail.dao.UpdatePreferredEmailProcedure.java

public UpdatePreferredEmailProcedure(DataSource dataSource) {
    super(dataSource, "msnhremail.UPDATE_FROM_PORTAL");

    this.declareParameter(new SqlParameter("email", Types.VARCHAR));
    this.declareParameter(new SqlParameter("pvi", Types.VARCHAR));
    this.declareParameter(new SqlParameter("emplid", Types.VARCHAR));

    this.compile();
}

From source file:com.bigdata.etl.util.DwUtil.java

public static void bulkInsert(String tableName, List<Map<String, String>> lst) {

    ResultSet rs = null;/*from  w  w  w .j av  a2  s  .c  o  m*/
    java.sql.Statement stmt = null;

    try (java.sql.Connection conn = DataSource.getConnection()) {
        stmt = conn.createStatement();
        rs = stmt.executeQuery("select top 0 * from " + tableName);
        try (SQLServerBulkCopy bulk = new SQLServerBulkCopy(url + "user=" + user + ";password=" + password)) {
            SQLServerBulkCopyOptions sqlsbc = new SQLServerBulkCopyOptions();
            sqlsbc.setBulkCopyTimeout(60 * 60 * 1000);
            bulk.setBulkCopyOptions(sqlsbc);
            bulk.setDestinationTableName(tableName);
            ResultSetMetaData rsmd = rs.getMetaData();
            if (lst == null) {
                return;
            }
            // System.out.println(LocalTime.now() + " "+Thread.currentThread().getId()+" "+lst.size());
            try (CachedRowSetImpl x = new CachedRowSetImpl()) {
                x.populate(rs);
                for (int k = 0; k < lst.size(); k++) {
                    Map<String, String> map = lst.get(k);
                    x.last();
                    x.moveToInsertRow();
                    for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                        String name = rsmd.getColumnName(i).toUpperCase();
                        int type = rsmd.getColumnType(i);//package java.sql.Type?

                        try {
                            switch (type) {
                            case Types.VARCHAR:
                            case Types.NVARCHAR:
                                int len = rsmd.getColumnDisplaySize(i);
                                String v = map.get(name);
                                if (map.containsKey(name)) {
                                    x.updateString(i, v.length() > len ? v.substring(0, len) : v);
                                } else {
                                    x.updateNull(i);
                                }
                                break;
                            case Types.BIGINT:
                                if (map.containsKey(name) && map.get(name).matches("\\d{1,}")) {
                                    x.updateLong(i, Long.valueOf(map.get(name)));
                                } else {
                                    //   x.updateLong(i, 0);
                                    x.updateNull(i);
                                }
                                break;
                            case Types.FLOAT:
                                if (map.containsKey(name) && map.get(name).matches("([+-]?)\\d*\\.\\d+$")) {
                                    x.updateFloat(i, Float.valueOf(map.get(name)));
                                } else {
                                    x.updateNull(i);

                                }
                                break;
                            case Types.DOUBLE:
                                if (map.containsKey(name) && map.get(name).trim().length() > 0
                                        && StringUtils.isNumeric(map.get(name))) {
                                    x.updateDouble(i, Double.valueOf(map.get(name)));
                                } else {
                                    x.updateNull(i);
                                }
                                break;

                            case Types.INTEGER:
                                if (map.containsKey(name) && map.get(name).matches("\\d{1,}")) {
                                    x.updateInt(i, Integer.valueOf(map.get(name)));
                                } else {
                                    x.updateNull(i);
                                }
                                break;

                            default:
                                throw new RuntimeException("? " + type);
                            }
                            /*
                            if(map.containsKey("SYS_TELECOM"))
                            System.err.println(map.get("SYS_TELECOM"));
                             */
                        } catch (RuntimeException | SQLException e) {
                            Logger.getLogger(DwUtil.class.getName()).log(Level.SEVERE,
                                    "? name=" + name + " v=" + map.get(name), e);
                        }

                    }
                    x.insertRow();
                    x.moveToCurrentRow();
                    //x.acceptChanges();
                }

                long start = System.currentTimeMillis();
                bulk.writeToServer(x);
                long end = System.currentTimeMillis();
                System.out.println(LocalTime.now() + " " + Thread.currentThread().getId() + " "
                        + (end - start) + "ms" + " " + x.size());
            }
        }

    } catch (SQLException e) {
        Logger.getLogger(DwUtil.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(DwUtil.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

From source file:net.sourceforge.vulcan.spring.jdbc.BuildQuery.java

public BuildQuery(DataSource dataSource) {
    this(dataSource, true);
    setSql(HistoryQueryBuilder.BUILD_INFO_SQL + "where uuid = ?");
    declareParameter(new SqlParameter("uuid", Types.VARCHAR));
    compile();/*from www  .  j a v a2s .  co  m*/
}

From source file:org.smigo.JdbcTestDao.java

@Override
public void removeEmail(String email) {
    String removeEmailSql = "UPDATE users SET email = NULL WHERE email = ?";
    jdbcTemplate.update(removeEmailSql, new Object[] { email }, new int[] { Types.VARCHAR });
}

From source file:at.alladin.rmbt.db.fields.StringField.java

@Override
public void getField(final PreparedStatement ps, final int idx) throws SQLException {
    if (value == null)
        ps.setNull(idx, Types.VARCHAR);
    else/*from  ww  w.ja v  a 2  s . c  o m*/
        ps.setString(idx, value);
}

From source file:com.antsdb.saltedfish.sql.DataType.java

public static DataType varchar(int length) {
    return new TypeString("_varchar", length, Types.VARCHAR);
}

From source file:org.zalando.stups.jpa.example.sp.ExampleSP.java

public ExampleSP(final DataSource dataSource) {
    LOG.info("inside NextNumberStoredProcedure datasource: {}", dataSource);

    setDataSource(dataSource);/*  w  w  w  . ja v  a2 s .  c om*/
    setFunction(true);
    setSql(STORED_PROCEDURE_NAME);
    declareParameter(new SqlParameter(IN_PARAMETER_NAME, Types.OTHER));
    declareParameter(new SqlOutParameter(OUT_PARAMETER_NAME, Types.VARCHAR));
    compile();
}

From source file:com.adaptris.core.services.jdbc.types.StringColumnTranslatorTest.java

@Test
public void testAsDoubleTranslator() throws Exception {
    JdbcResultRow row = new JdbcResultRow();
    row.setFieldValue("testField", new Double(111), Types.VARCHAR);

    {//from  ww w .  j a v  a 2s  .co m
        String translated = translator.translate(row, 0);
        assertEquals("111.0", translated);
    }
    {
        String translated = translator.translate(row, "testField");
        assertEquals("111.0", translated);
    }
}