у меня проблема при подключении к базе данных с помощью javafx - PullRequest
0 голосов
/ 23 апреля 2019

Я новичок в javafx, и у меня иногда возникают проблемы при подключении к базе данных

, например:

 *
 * @author TOSHIBA
 */
public class authentification {



    //**


      authentification(){


    }

    public boolean authentification(String username,String pass) {

         String sql = "SELECT * FROM administrateur WHERE pseudo = ? and mdp = ?";

         boolean suucess=false;
         try {

             ConnectionClass connectionClass = new ConnectionClass();
             Connection connection = connectionClass.getConnection();
             PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, username);
             preparedStatement.setString(2, pass);
             ResultSet resultSet = preparedStatement.executeQuery();

             if (!resultSet.next()) {
                 suucess= true;  

           } 
       } catch (Exception e) {
             e.printStackTrace();
         }
        return suucess;


    }
}

1 Ответ

0 голосов
/ 24 апреля 2019
//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();




}

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...