Java JDBC Derby Connection getTables(File database)

Here you can find the source of getTables(File database)

Description

get Tables

License

Open Source License

Declaration

static public ArrayList<String> getTables(File database)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException 

Method Source Code

//package com.java2s;
/**/*from  w w  w . ja v a2s  . c o m*/
 * OWASP GoatDroid Project
 * 
 * This file is part of the Open Web Application Security Project (OWASP)
 * GoatDroid project. For details, please see
 * https://www.owasp.org/index.php/Projects/OWASP_GoatDroid_Project
 *
 * Copyright (c) 2012 - The OWASP Foundation
 * 
 * GoatDroid is published by OWASP under the GPLv3 license. You should read and accept the
 * LICENSE before you use, modify, and/or redistribute this software.
 * 
 * @author Jack Mannino (Jack.Mannino@owasp.org https://www.owasp.org/index.php/User:Jack_Mannino)
 * @created 2012
 */

import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;

import java.sql.ResultSet;

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

public class Main {
    static public ArrayList<String> getTables(File database)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {

        String DB_CONNECTION_STRING = "jdbc:derby:" + database;

        Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        Connection conn = (Connection) DriverManager.getConnection(DB_CONNECTION_STRING);
        DatabaseMetaData dbmd = conn.getMetaData();
        ResultSet rs = dbmd.getTables(null, null, null, null);
        ArrayList<String> tables = new ArrayList<String>();
        while (rs.next()) {
            /*
             * We only want application tables Don't really care about the rest
             * of the schema
             */
            if (rs.getString("TABLE_SCHEM").equals("APP"))
                tables.add(rs.getString("TABLE_NAME"));
        }
        conn.close();
        return tables;
    }
}

Related

  1. getDriver(String className)
  2. getLocalConnection()
  3. getRowsFromDatabase(Connection con, int numberOfRows, boolean reuseConnection, String driver, String dsn, String user, String password, String tableName, String whereString, String orderByString, String groupByString)
  4. getSessionIds()
  5. getSize2()
  6. printStats(String statstring)
  7. removeUnitDB()
  8. saveContact(String fName, String lName)
  9. startDerby()