Java SQL Type loadAllTypesData(Connection conn)

Here you can find the source of loadAllTypesData(Connection conn)

Description

Load only one record

License

Open Source License

Declaration

public static void loadAllTypesData(Connection conn) throws SQLException 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.sql.Time;
import java.sql.Timestamp;

public class Main {
    /**//www .  j av a2  s . c  o  m
     * Load only one record
     */
    public static void loadAllTypesData(Connection conn) throws SQLException {
        try (PreparedStatement statement = conn
                .prepareStatement("insert into ALL_TYPES values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")) {
            statement.setShort(1, (short) 32767);
            statement.setInt(2, 2147483647);
            statement.setLong(3, 9223372036854775807l);
            statement.setFloat(4, 1.11111111f);
            statement.setDouble(5, 2.222222222);
            statement.setBigDecimal(6, new BigDecimal("1234567890.1234567890"));
            statement.setString(7, "abcd");
            statement.setString(8, "abcdefg");

            Blob blob = conn.createBlob();
            byte[] bytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            blob.setBytes(1, bytes);
            statement.setBlob(9, blob);

            Clob clob = conn.createClob();
            clob.setString(1, "abcdefg");
            statement.setClob(10, clob);

            statement.setDate(11, Date.valueOf("2016-12-28"));
            statement.setTime(12, Time.valueOf("14:30:33"));
            statement.setTimestamp(13, Timestamp.valueOf("2016-12-28 14:31:56.12345"));
            statement.setBoolean(14, true);

            statement.executeUpdate();
        }

        if (!conn.getAutoCommit()) {
            conn.commit();
        }
    }
}

Related

  1. isValidReaderOrStream(final Object o)
  2. isXMLType(int type)
  3. jdbcType2javaType(int jdbcType)
  4. jdbcTypeToKylinDataType(int sqlType)
  5. listToJson(List list)
  6. loadTestDataForEveryType(Connection conn)
  7. mapECLtype2SQLtype(String ecltype)
  8. mapType(Class javaType)
  9. mapXSDTypeName2SQLtype(String xsdtype)

  10. HOME | Copyright © www.java2s.com 2016