Java SQL Type getViewIdsForTypes(Connection connection, String... types)

Here you can find the source of getViewIdsForTypes(Connection connection, String... types)

Description

get View Ids For Types

License

Open Source License

Declaration

public static List<Long> getViewIdsForTypes(Connection connection,
            String... types) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Long> getViewIdsForTypes(Connection connection,
            String... types) throws SQLException {
        ArrayList<Long> ids = new ArrayList<>();
        StringBuilder sql = new StringBuilder("SELECT id FROM portti_view");
        if (types != null && types.length > 0) {
            sql.append(" WHERE type IN (?");
            for (int i = 1; i < types.length; ++i) {
                sql.append(", ?");
            }/*  ww  w. j  ava 2s.  c  o m*/
            sql.append(")");

        }
        try (final PreparedStatement statement = connection
                .prepareStatement(sql.toString())) {
            if (types != null) {
                for (int i = 0; i < types.length; ++i) {
                    statement.setString(i + 1, types[i]);
                }
            }
            try (ResultSet rs = statement.executeQuery()) {
                while (rs.next()) {
                    ids.add(rs.getLong("id"));
                }
            }
        }
        return ids;
    }
}

Related

  1. getTypeNameForJDBCType(int jdbcType)
  2. getTypeStringForObject(Object o)
  3. getUDTOwner(String typeName, String dbName, Connection conn)
  4. getValueType(String inputValue)
  5. getVarcharTypeString(Connection conn, int length)
  6. indexOf(Object[] array, Object objectToFind)
  7. invokeJdbcMethod(Class interfaceClass, String methodName, Class[] argTypes, Object target, Object[] args)
  8. isBinary(int dataType)
  9. isBinary(int jdbcType)