All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bixuebihui.jdbc.JDBCUtils Maven / Gradle / Ivy

Go to download

a fast small database connection pool and a active record flavor mini framework

There is a newer version: 1.15.3.3
Show newest version
package com.bixuebihui.jdbc;

import com.bixuebihui.util.DbUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;

/**
 * 读取数据库表或视图,处理oracle大字段
 *
 * @author xingwx
 * @version $Id: $Id
 */
public class JDBCUtils {

    /**
     * Constant mLog
     */
    protected static final Logger LOG = LoggerFactory.getLogger(JDBCUtils.class);

    private JDBCUtils(){
        throw new IllegalAccessError("this is a utils class");
    }

    /**
     * 

tableOrViewExists.

* * @param catalog a {@link java.lang.String} object. * @param schemaPattern a {@link java.lang.String} object. * @param tableName a {@link java.lang.String} object. * @param conn a {@link java.sql.Connection} object. * @return a boolean. * @throws java.sql.SQLException if any. */ public static boolean tableOrViewExists(String catalog, String schemaPattern, String tableName, Connection conn) throws SQLException { String[] tableTypes = { "TABLE", "VIEW" }; DatabaseMetaData metaData = conn.getMetaData(); ResultSet tables = null; boolean res; try { tables = metaData.getTables(catalog, schemaPattern, tableName, tableTypes); res = tables.next(); } finally { close(tables); } return res; } /** *

columnOfTableExists.

* * @param catalog a {@link java.lang.String} object. * @param schemaPattern a {@link java.lang.String} object. * @param tableName a {@link java.lang.String} object. * @param columnName a {@link java.lang.String} object. * @param conn a {@link java.sql.Connection} object. * @return a boolean. * @throws java.sql.SQLException if any. */ public static boolean columnOfTableExists(String catalog, String schemaPattern, String tableName, String columnName, Connection conn) throws SQLException { DatabaseMetaData metaData = conn.getMetaData(); ResultSet column = null; boolean res; try { column = metaData.getColumns(catalog, schemaPattern, tableName, columnName); res = column.next(); } finally { close(column); } return res; } /** *

close.

* * @param stmt a {@link java.sql.Statement} object. */ public static void close(Statement stmt) { DbUtils.closeQuietly(stmt); } /** *

close.

* * @param rs a {@link java.sql.ResultSet} object. */ public static void close(ResultSet rs) { DbUtils.closeQuietly(rs); } /** *

close.

* * @param conn a {@link java.sql.Connection} object. */ public static void close(Connection conn) { DbUtils.closeQuietly(conn); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy