Package java.sql

Examples of java.sql.DatabaseMetaData


    statements.add(statement);
    return statement;
  }

  public boolean doesTableExist(String table) throws SQLException {
    DatabaseMetaData meta = connection.getMetaData();
    ResultSet result = meta.getTables(null, null, table, null);
    boolean res = result.next();
    result.close();
    return res;
  }
View Full Code Here


    return res;
  }


  public boolean doesColumnExist(String table, String column) throws SQLException {
    DatabaseMetaData meta = connection.getMetaData();
    ResultSet result = meta.getColumns(null, null, table, column);
    boolean res = result.next();
    result.close();
    return res;
  }
View Full Code Here

    result.close();
    return res;
  }
 
  public int getColumnLength(String table, String column) throws SQLException {
    DatabaseMetaData meta = connection.getMetaData();
    ResultSet result = meta.getColumns(null, null, table, column);
    if (result.next()) {
      return result.getInt("COLUMN_SIZE");
    }
    return -1;
  }
View Full Code Here

  }

  @Override
    protected Connection createConnection(Properties connInfo) throws DatabaseConnectionException {
      Connection con = super.createConnection(connInfo);
    DatabaseMetaData meta;
        try {
          meta = con.getMetaData();
      String name = meta.getDatabaseProductName();
        if (name.toLowerCase(Locale.ENGLISH).indexOf("mysql") < 0) {
          logger.warn("Using MySQLDatabaseAdapter to connect to " + name);
        }
        } catch (SQLException e) {
          logger.error(e, e);
View Full Code Here

  }

  @Override
  protected Connection createConnection(Properties connInfo) throws DatabaseConnectionException {
    Connection con = super.createConnection(connInfo);
    DatabaseMetaData meta;
    try {
      meta = con.getMetaData();
      String name = meta.getDatabaseProductName();
      if (name.toLowerCase(Locale.ENGLISH).indexOf("h2") < 0) {
        logger.warn("Using H2DatabaseAdapter to connect to " + name);
      }
      if (connInfo.getProperty("jdbc_url", "").toLowerCase(Locale.ENGLISH).indexOf(";mode=") > -1) {
        logger.warn("The configuration parameter jdbc_url configures H2 for compatibility mode. This is likely to cause trouble.");
View Full Code Here

    return mySql;
  }

  @Override
  public boolean doesTableExist(String table) throws SQLException {
    DatabaseMetaData meta = connection.getMetaData();
    ResultSet result = meta.getTables(null, null, table.toUpperCase(Locale.ENGLISH), null);
    boolean res = result.next();
    result.close();
    return res;
  }
View Full Code Here

    return res;
  }

  @Override
  public boolean doesColumnExist(String table, String column) throws SQLException {
    DatabaseMetaData meta = connection.getMetaData();
    ResultSet result = meta.getColumns(null, null, table.toUpperCase(),
        column.toUpperCase(Locale.ENGLISH));
    boolean res = result.next();
    result.close();
    return res;
  }
View Full Code Here

    return res;
  }

  @Override
  public int getColumnLength(String table, String column) throws SQLException {
    DatabaseMetaData meta = connection.getMetaData();
    ResultSet result = meta.getColumns(null, null, table.toUpperCase(Locale.ENGLISH),
        column.toUpperCase(Locale.ENGLISH));
    if (result.next()) {
      return result.getInt("COLUMN_SIZE");
    }
    return -1;
View Full Code Here

     *        database
     * @throws Exception on any error
     */
    public void dumpTable(PrintWriter writer, JDBCConnectionImpl conx, char quoteChar, String[] tables) throws Exception {
        Connection jdbcConnection = conx.getConnection();
        DatabaseMetaData dbMetaData = jdbcConnection.getMetaData();

        if (tables == null) {
            ResultSet rs = dbMetaData.getTables(null, null, null, null);
            try {
                while (rs.next()) {
                    String tableName = rs.getString("TABLE_NAME");
                    String tableType = rs.getString("TABLE_TYPE");
                    if (tableType.equalsIgnoreCase("TABLE")) {
                        dumpTable(writer, conx, quoteChar, new String[] { tableName });
                    }
                }
            } finally {
                rs.close();
            }
        } else {
            for (int i = 0; i < tables.length; i++) {
                String tableName = tables[i];
                log.info("Dumping table creation for " + tableName);
                writer.println("CREATE TABLE " + tableName + " (");
                boolean first = true;

                // Columns
                ResultSet rs2 = dbMetaData.getColumns(null, null, tableName, "%");
                try {
                    while (rs2.next()) {
                        if (first) {
                            first = false;
                        } else {
                            writer.println(",");
                        }
                        String columnName = rs2.getString("COLUMN_NAME");
                        String columnType = rs2.getString("TYPE_NAME");
                        int columnSize = rs2.getInt("COLUMN_SIZE");
                        String nullable = rs2.getString("IS_NULLABLE");
                        String nullString = "NULL";
                        if ("NO".equalsIgnoreCase(nullable)) {
                            nullString = "NOT NULL";
                        }
                        writer.print("    " + columnName + " " + columnType);
                        if (columnSize != 0) {
                            if (columnType.equalsIgnoreCase("varchar") && columnSize > 255) {
                                columnSize = 255;
                            }
                            writer.print(" (" + columnSize + ")");
                        }
                        writer.print(" " + nullString);

                    }
                } finally {
                    rs2.close();
                }

                // Keys
                try {
                    rs2 = dbMetaData.getPrimaryKeys(null, null, tableName);
                    String primaryKeyName = null;
                    StringBuffer primaryKeyColumns = new StringBuffer();
                    while (rs2.next()) {
                        String thisKeyName = rs2.getString("PK_NAME");
                        if ((thisKeyName != null && primaryKeyName == null) || (thisKeyName == null && primaryKeyName != null)
View Full Code Here

     *        database
     * @throws Exception on any error
     */
    public void dumpData(PrintWriter writer, JDBCConnectionImpl conx, char quoteChar, String[] tables) throws Exception {
        Connection jdbcConnection = conx.getConnection();
        DatabaseMetaData dbMetaData = jdbcConnection.getMetaData();

        if (tables == null) {
            ResultSet rs = dbMetaData.getTables(null, null, null, null);
            try {
                while (rs.next()) {
                    String tableName = rs.getString("TABLE_NAME");
                    String tableType = rs.getString("TABLE_TYPE");
                    if (tableType.equalsIgnoreCase("TABLE")) {
View Full Code Here

TOP

Related Classes of java.sql.DatabaseMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.