daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Feb 17th, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ConnectDatabase {    
  2.    ConnectDatabase(String username, String password , String a) throws SQLException  {
  3.        Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/ai", username, password);
  4.        Statement stmt =  con.createStatement();    // ResultSet FromResultSet = stmt.executeQuery("SELECT * FROM *");      
  5.        ArrayList<String> TableName=new ArrayList<>();      
  6.        DatabaseMetaData md   = con.getMetaData();      
  7.        ResultSet rs = md.getTables(null, null, "%", null);  
  8.        while (rs.next()){      
  9.        TableName.add(rs.getString(3));      
  10.  
  11.      }
  12.        String[] Tablenames= new String[TableName.size()];      
  13.        String[] TableNames = TableName.toArray(Tablenames);
  14.  
  15. System.out.println("Database checking done!");
  16. con.close();
  17. }
  18.    
  19. public String[] getTableNames(String username, String password , String a) throws SQLException{
  20.  Connection DatabaseConnection = DriverManager.getConnection("jdbc:derby://localhost:1527/ai", username, password);
  21.      DatabaseMetaData DatabaseInfo   = DatabaseConnection.getMetaData();
  22.       ResultSet FromResultSet = DatabaseInfo.getTables(null, null, "%", null);  
  23.       ArrayList<String> TableNameArrayList=new ArrayList<>();
  24.  
  25.       while (FromResultSet.next()){        
  26.          TableNameArrayList.add(FromResultSet.getString(3));      
  27.  
  28.      }
  29.      String[] StringArrayObject= new String[TableNameArrayList.size()];      
  30.       String[] TableNameStringArray = TableNameArrayList.toArray(StringArrayObject);
  31.     DatabaseConnection.close();
  32.       return TableNameStringArray;
  33.  
  34.  }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top