Java JDBC Database Metadata adjustIdentifierCase(String identifier, Connection conn)

Here you can find the source of adjustIdentifierCase(String identifier, Connection conn)

Description

Adjusts an SQL identifier to correct case according to the database convention.

License

Open Source License

Parameter

Parameter Description
identifier a SQL identifier.
conn a JDBC connection

Exception

Parameter Description
SQLException an exception

Return

case-adjusted identifier

Declaration

public static String adjustIdentifierCase(String identifier, Connection conn) throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.Connection;
import java.sql.DatabaseMetaData;

import java.sql.SQLException;

public class Main {
    /**// w  ww.j  ava2 s.  c  o m
     * Adjusts an SQL identifier to correct case according to the database convention.
     * 
     * @param identifier a SQL identifier.
     * @param conn a JDBC connection
     * @return case-adjusted identifier
     * @throws SQLException
     */
    public static String adjustIdentifierCase(String identifier, Connection conn) throws SQLException {
        DatabaseMetaData md = conn.getMetaData();
        if (!md.storesMixedCaseIdentifiers() && identifier != null) {
            if (md.storesUpperCaseIdentifiers()) {
                return identifier.toUpperCase();
            }
            if (md.storesLowerCaseIdentifiers()) {
                return identifier.toLowerCase();
            }
        }
        return identifier;
    }
}

Related

  1. createHsqlPlSchemaIfNecessary(Connection con)
  2. getAllTables(Connection connection)
  3. getAllTables(Connection connection)
  4. getCatalogs(Connection c)