Java SQL Type getUDTOwner(String typeName, String dbName, Connection conn)

Here you can find the source of getUDTOwner(String typeName, String dbName, Connection conn)

Description

get UDT Owner

License

Open Source License

Parameter

Parameter Description
typeName a parameter
dbName a parameter
conn a parameter

Exception

Parameter Description
SQLException an exception

Declaration

public static String getUDTOwner(String typeName, String dbName,
        Connection conn) throws SQLException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc./*from ww  w .j  a v a2 s. co  m*/
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    linsong - initial API and implementation
 *******************************************************************************/

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**
     * 
     * @param typeName
     * @param dbName
     * @param conn
     * @return
     * @throws SQLException
     * @author sfyu
     */
    public static String getUDTOwner(String typeName, String dbName,
            Connection conn) throws SQLException {

        if (typeName != null && !typeName.trim().equals("")) {
            Statement stat = null;
            ResultSet rs = null;
            String ownerName = null;
            try {
                String query = "SELECT U.name owner_name,T.name udt_name, PHY.name udt_sys_name, T.length udt_length,"
                        + "T.prec udt_precision, T.scale udt_scale, T.allownulls udt_allow_nulls, T.ident udt_is_identity,"
                        + "(SELECT DO.name + '.' + object_name(T.tdefault,db_id('"
                        + dbName
                        + "')) "
                        + "FROM "
                        + dbName
                        + ".dbo.sysusers DO "
                        + "WHERE DO.uid=(SELECT uid from "
                        + dbName
                        + ".dbo.sysobjects where id = T.tdefault)) "
                        + "udt_default_name, "
                        + "(SELECT RO.name + '.' + object_name((case when T.domain<>0 then T.domain else T.accessrule end),db_id('pubs2')) "
                        + "FROM "
                        + dbName
                        + ".dbo.sysusers RO "
                        + "WHERE RO.uid = (SELECT uid from dbo.sysobjects where id  = T.domain OR id = T.accessrule)) "
                        + "udt_rule_name "
                        + "FROM  "
                        + dbName
                        + ".dbo.systypes T, "
                        + dbName
                        + ".dbo.sysusers U, "
                        + dbName
                        + ".dbo.systypes PHY "
                        + "WHERE T.uid = U.uid AND PHY.usertype =(SELECT min(usertype) FROM "
                        + dbName
                        + ".dbo.systypes WHERE type = T.type ) "
                        + "AND T.type = PHY.type AND T.usertype >= 100 AND T.name like '"
                        + typeName + "'";
                stat = conn.createStatement();
                rs = stat.executeQuery(query.toString());
                if (rs.next()) {
                    ownerName = rs.getString("owner_name");
                }
            } catch (SQLException se) {
                throw se;
            } finally {
                if (rs != null) {
                    rs.close();
                }
                if (stat != null) {
                    stat.close();
                }
            }
            return ownerName;
        }
        return null;
    }
}

Related

  1. getTypeforValue(int type)
  2. getTypeName(int dataType)
  3. getTypeName(int typeNumber)
  4. getTypeNameForJDBCType(int jdbcType)
  5. getTypeStringForObject(Object o)
  6. getValueType(String inputValue)
  7. getVarcharTypeString(Connection conn, int length)
  8. getViewIdsForTypes(Connection connection, String... types)
  9. indexOf(Object[] array, Object objectToFind)