//Create Dtbconnectin .java
//Create your database with Mysql
package application;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author 50CENT
*/
public class Dbconnection {
public Connection connect(){
try {
String url="jdbc:mysql://localhost:3306/mysql";
String user="root";
String password ="";
Class.forName("com.mysql.jdbc.Driver");
Connection conn = (Connection) DriverManager.getConnection(url, user, password);
return conn;
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(Dbconnection.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
} }
//then go to your Controller class
package application;
import java.net.URL;
import java.sql.Connection;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
/**
*
* @author 50CENT
*/
public class SIGNUPController implements Initializable {
@FXML
private Label label;
@FXML
private TableColumn<User, String> columnName;
@FXML
private TableColumn<User, String> columnLast;
@FXML
private TableColumn<User, Integer> columnID;
@FXML
private TableColumn<User, String> columnGender;
@FXML
private TableColumn<User, Object> columnBirthday;
@FXML
private TableColumn<User, String> columnEmail;
@FXML
private TableColumn<User, Integer> columnPhonenumber;
@FXML
private TableColumn<User, String> columnPassword;
@FXML
private Button btnLoad ;
private ObservableList <User> data ;
private Dbconnection dc ;
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
dc=new Dbconnection ();
}
@FXML
private void LoadDataFromDatabase (ActionEvent event)
{
Connection conn =dc.connect();
data =FXCollections.observableArrayList();
}
}