I have an airline system mangement project where I work with multiple databases. The first one ( db ) works fine. When I try to implement the second one i got an 'access denied' message.
I copy-pasted the code from the first one but I replaced the name of the first database with the name of the second one as you can see and I changed the column names for the specific table.
Can someone help me with this one?
I tried adding skip-grant-tables
into my.ini ) '
package sample.my_project_uvt;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class MySqlConnectPassengers {
enter code here
Connection conn = null;
public static Connection ConnectDb(){
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/passengers");
JOptionPane.showMessageDialog(null,"ConnectionEstablished");
return conn;
}catch (Exception e)
{
JOptionPane.showMessageDialog(null,e);
return null;
}
}
public static ObservableList<passengers> getDatauser(){
Connection conn = ConnectDb();
ObservableList<passengers>list= FXCollections.observableArrayList();
try{
PreparedStatement ps = conn.prepareStatement("SELECT * FROM `passengers`;");
ResultSet rs = ps.executeQuery();
while(rs.next())
{
list.add(new passengers(Integer.parseInt(rs.getString("ID")),rs.getString("NAME"),rs.getString("EMAIL"),rs.getString("FLIGHT_ID"),rs.getString("PHONE")));
}
}catch (Exception e )
{
}
return list;
}
}
package sample.my_project_uvt;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.event.ActionEvent;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ResourceBundle;
public class Passagers_controller implements Initializable {
public Passagers_controller(){
}
@FXML
private Button buttonMenu;
@FXML
private Button buttonBook;
@FXML
private TableColumn<passengers, String> col_email;
@FXML
private TableColumn<passengers, String> col_flight;
@FXML
private TableColumn<passengers, Integer> col_id;
@FXML
private TableColumn<passengers, String> col_name;
@FXML
private TableColumn<passengers, String> col_phone;
@FXML
private TableView<passengers> table_users;
ObservableList<passengers> listM;
int index = -1;
Connection conn = null;
ResultSet rs=null;
PreparedStatement pst = null;
@FXML
public void userChangeBook(ActionEvent event) throws IOException {
HelloApplication m = new HelloApplication();
m.changeScene("Book.fxml");
}
public void userChangeMenu(ActionEvent event) throws IOException {
HelloApplication m = new HelloApplication();
m.changeScene("MENU.fxml");
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
col_id.setCellValueFactory(new PropertyValueFactory<passengers,Integer>("ID"));
col_name.setCellValueFactory(new PropertyValueFactory<passengers,String>("NAME"));
col_email.setCellValueFactory(new PropertyValueFactory<passengers,String>("EMAIL"));
col_flight.setCellValueFactory(new PropertyValueFactory<passengers,String>("FLIGHT_ID"));
col_phone.setCellValueFactory(new PropertyValueFactory<passengers,String>("PHONE"));
listM=MySqlConnectPassengers.getDatauser();
table_users.setItems(listM);
}
}
package sample.my_project_uvt;
public class passengers {
int ID;
String NAME, EMAIL, FLIGHT_ID,PHONE;
public passengers(int ID, String NAME, String EMAIL, String FLIGHT_ID, String PHONE) {
this.ID = ID;
this.NAME = NAME;
this.EMAIL = EMAIL;
this.FLIGHT_ID = FLIGHT_ID;
this.PHONE = PHONE;
}
public int getID() {return ID;}
public String getNAME() {return NAME;}
public String getEMAIL() {return EMAIL;}
public String getFLIGHT_ID() {return FLIGHT_ID;}
public String getPHONE() {return PHONE;}
public void setID(int ID) {
this.ID = ID;
}
public void setNAME(String NAME) {
this.NAME = NAME;
}
public void setEMAIL(String EMAIL) {
this.EMAIL = EMAIL;
}
public void setFLIGHT_ID(String FLIGHT_ID) {
this.FLIGHT_ID = FLIGHT_ID;
}
public void setPHONE(String PHONE) {
this.PHONE = PHONE;
}
}