Java SQL Table normalizeTableName(String table, Connection con)

Here you can find the source of normalizeTableName(String table, Connection con)

Description

normalize Table Name

License

Apache License

Declaration

public static String normalizeTableName(String table, Connection con) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public static String normalizeTableName(String table, Connection con) throws SQLException {
        for (String t : getTables(con)) {
            if (t.equalsIgnoreCase(table)) {
                return t;
            }//from  ww w.  j  a v  a2 s.co m
        }
        return table;
    }

    public static List<String> getTables(Connection con) throws SQLException {
        String[] types = { "TABLE" };
        ResultSet rs = con.getMetaData().getTables(null, null, "%", types);
        List<String> tables = new ArrayList<String>();
        while (rs.next()) {
            tables.add(rs.getString("TABLE_NAME"));
        }
        rs.close();
        return tables;

    }
}

Related

  1. hasTable(Connection conn, String schemaName, String tableName)
  2. hasTable(String TableName, Connection conn)
  3. isExistsDerbyTable(Connection derbyConnection, String schema, String table)
  4. isFileImportable(File file, String prefix)
  5. isTableEmpty(Connection con, String schemaName, String tableName)
  6. parse(Connection connection, String tableName, String type)
  7. queryAllFromTable(String tableName)
  8. quoteSchemaTable(Connection conn, String schema, String table)
  9. truncateTable(Connection conn)