Guest User

Untitled

a guest
Dec 23rd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import java.net.URL;
  2. import java.sql.DatabaseMetaData;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.util.ArrayList;
  6. import java.util.ResourceBundle;
  7.  
  8. import javafx.collections.FXCollections;
  9. import javafx.collections.ObservableArray;
  10. import javafx.collections.ObservableList;
  11. import javafx.fxml.FXML;
  12. import javafx.scene.control.ChoiceBox;
  13. import javafx.scene.control.Label;
  14. import javafx.scene.control.TableView;
  15.  
  16. public class Controller {
  17.  
  18. @FXML
  19. private ResourceBundle resources;
  20.  
  21. @FXML
  22. private URL location;
  23.  
  24. @FXML
  25. private TableView<?> table;
  26.  
  27. @FXML
  28. private ChoiceBox<String> choice;
  29.  
  30. @FXML
  31. void initialize() {
  32. ObservableList<String> tableNames = FXCollections.observableArrayList(getTablename());
  33. choice.setItems(tableNames);
  34. }
  35.  
  36. ArrayList<String> getTablename() {
  37. DB db = new DB();
  38.  
  39. ArrayList<String> tableNames = new ArrayList<>();
  40. try {
  41. ResultSet rs = null;
  42. DatabaseMetaData meta = db.connection.getMetaData();
  43. rs = meta.getTables(null, null, null, new String[]{"TABLE"});
  44.  
  45. while (rs.next()) {
  46. String tableName = rs.getString("TABLE_NAME");
  47. if (!tableName.equals("sys_config"))
  48. tableNames.add(tableName);
  49. }
  50. } catch (
  51. SQLException e) {
  52. e.printStackTrace();
  53. }
  54.  
  55. return tableNames;
  56. }
  57. }
  58.  
  59. public class DB {
  60.  
  61. final String URL = "jdbc:mysql://localhost:3306/mydbtest?useUnicode=true&useSSL=true&useJDBCCompliantTimezoneShift=true" +
  62. "&useLegacyDatetimeCode=false&serverTimezone=UTC";
  63.  
  64. final String USER = "root";
  65. final String PASS = "f3HZbDLW";
  66.  
  67. public Connection connection;
  68.  
  69. public DB() {
  70. try {
  71. connection = DriverManager.getConnection(URL, USER, PASS);
  72. if (!connection.isClosed()) {
  73. System.out.println("Соединение с БД установлено");
  74. }
  75. } catch (SQLException e) {
  76. System.out.println("ХУЙ");
  77. }
  78. }
  79.  
  80. public Statement getStatement() {
  81. try {
  82. return connection.createStatement();
  83. } catch (SQLException e) {
  84. System.err.println("Failed to get statement");
  85. e.printStackTrace();
  86. return null;
  87. }
  88. }
  89.  
  90. public Connection getConnection() {
  91. return connection;
  92. }
  93. }
Add Comment
Please, Sign In to add comment