Java Utililty Methods SQL Type

List of utility methods to do SQL Type

Description

The list of methods to do SQL Type are organized into topic(s).

Method

InputStreamconvertToStream(final Object o)
convert To Stream
if (o instanceof byte[]) {
    return new ByteArrayInputStream((byte[]) o);
if (o instanceof Blob) {
    final Blob b = (Blob) o;
    try {
        return b.getBinaryStream();
    } catch (SQLException e) {
...
StringconvertToString(int datatype)
Converts the data type id to data type string
switch (datatype) {
case Types.ARRAY:
    return "ARRAY";
case Types.BIGINT:
    return "BIGINT";
case Types.BINARY:
    return "BINARY";
case Types.BIT:
...
intconvertType(final int type)
Types.ARRAY is not supported
switch (type) {
case Types.BIT:
case Types.BOOLEAN:
    return PG_TYPE_BOOL;
case Types.VARCHAR:
    return PG_TYPE_VARCHAR;
case Types.CHAR:
    return PG_TYPE_BPCHAR;
...
intconvertType(final int type, final String typeName)
Types.ARRAY is not supported
switch (type) {
case Types.BIT:
case Types.BOOLEAN:
    return PG_TYPE_BOOL;
case Types.VARCHAR:
    return PG_TYPE_VARCHAR;
case Types.CHAR:
    return PG_TYPE_BPCHAR;
...
voidcreateAllTypesTable(Connection conn)
Following several methods are setup and tearDown methods for ALL_TYPES table.
try (Statement statement = conn.createStatement()) {
    statement.execute(
            "create table ALL_TYPES (SMALL_INT_COL smallint, INT_COL integer, BIG_INT_COL bigint, REAL_COL real, DOUBLE_COL double,"
                    + "DECIMAL_COL decimal(20,10), CHAR_COL char(4), VARCHAR_COL varchar(8), BLOB_COL blob(16), CLOB_COL clob(16), DATE_COL date,"
                    + "TIME_COL time, TIMESTAMP_COL timestamp, BOOLEAN_COL boolean)");
int[]createArrTypSql(String[] arr)
create Arr Typ Sql
int[] types = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
    types[i] = Types.VARCHAR;
types[arr.length - 1] = Types.CHAR;
return types;
StringcreateSignature(Method m)
Extracts parameters from a given method object and formats the string names of the methods parameters into a compatible signature
StringBuffer sb = new StringBuffer();
Class[] params = m.getParameterTypes();
sb.append("(");
for (int i = 0; i < params.length; i++) {
    String str1 = params[i].getName();
    if (str1.equals("short")) 
        sb.append("S");
    else if (str1.equals("int"))
...
StringcreateSqlDataType(@Nonnull final String javaDataType)
Create the java.sql.Types type for the given Java datatype.
if ("boolean".equals(javaDataType) || "java.lang.Boolean".equals(javaDataType)) {
    return "java.sql.Types.BOOLEAN";
} else if ("byte".equals(javaDataType) || "java.lang.Byte".equals(javaDataType)) {
    return "java.sql.Types.TINYINT";
} else if ("short".equals(javaDataType) || "java.lang.Short".equals(javaDataType)) {
    return "java.sql.Types.SMALLINT";
} else if ("int".equals(javaDataType) || "java.lang.Integer".equals(javaDataType)) {
    return "java.sql.Types.INTEGER";
...
voidcreateTable2()
create Table
Connection conn = DriverManager.getConnection(protocol + dbName + ";create=true");
Statement st = conn.createStatement();
String sql = "create table whore2(id bigint  primary key,obj blob)";
st.execute(sql);
st.close();
conn.close();
voidcreateTestData()
create Test Data
java.sql.Connection jdbcConn = openJDBCConnection();
java.sql.Statement jdbcStmt = jdbcConn.createStatement();
String sql = "drop table " + TABLE_NAME;
try {
    jdbcStmt.execute(sql);
} catch (Exception e) {
sql = "create table " + TABLE_NAME + "(";
...