Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.URL;
- import java.sql.DatabaseMetaData;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.ResourceBundle;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableArray;
- import javafx.collections.ObservableList;
- import javafx.fxml.FXML;
- import javafx.scene.control.ChoiceBox;
- import javafx.scene.control.Label;
- import javafx.scene.control.TableView;
- public class Controller {
- @FXML
- private ResourceBundle resources;
- @FXML
- private URL location;
- @FXML
- private TableView<?> table;
- @FXML
- private ChoiceBox<String> choice;
- @FXML
- void initialize() {
- ObservableList<String> tableNames = FXCollections.observableArrayList(getTablename());
- choice.setItems(tableNames);
- }
- ArrayList<String> getTablename() {
- DB db = new DB();
- ArrayList<String> tableNames = new ArrayList<>();
- try {
- ResultSet rs = null;
- DatabaseMetaData meta = db.connection.getMetaData();
- rs = meta.getTables(null, null, null, new String[]{"TABLE"});
- while (rs.next()) {
- String tableName = rs.getString("TABLE_NAME");
- if (!tableName.equals("sys_config"))
- tableNames.add(tableName);
- }
- } catch (
- SQLException e) {
- e.printStackTrace();
- }
- return tableNames;
- }
- }
- public class DB {
- final String URL = "jdbc:mysql://localhost:3306/mydbtest?useUnicode=true&useSSL=true&useJDBCCompliantTimezoneShift=true" +
- "&useLegacyDatetimeCode=false&serverTimezone=UTC";
- final String USER = "root";
- final String PASS = "f3HZbDLW";
- public Connection connection;
- public DB() {
- try {
- connection = DriverManager.getConnection(URL, USER, PASS);
- if (!connection.isClosed()) {
- System.out.println("Соединение с БД установлено");
- }
- } catch (SQLException e) {
- System.out.println("ХУЙ");
- }
- }
- public Statement getStatement() {
- try {
- return connection.createStatement();
- } catch (SQLException e) {
- System.err.println("Failed to get statement");
- e.printStackTrace();
- return null;
- }
- }
- public Connection getConnection() {
- return connection;
- }
- }
Add Comment
Please, Sign In to add comment