1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
public class ConnectionDialog {
t_connect connexion;
// les différents titre des boutons du dialogue de connexion
static String[] optionNames = { "Connect" , "Cancel" };
public String text;
public boolean bool= false;;
String username;
String password;
String servername;
String port1;
String databaseName;
String driver1;
String server1;
// les TextFields pour la saisie des informations de connexion
JTextField userNameField;
JTextField passwordField;
JTextField serverNameField;
JTextField databaseNameField;
JComboBox serverField;
JComboBox driverField;
JComboBox portField;
// le Panel regroupant les "widgets" pour la connexion (TextFields
// et Labels)
JPanel connectionPanel;
Vector server;
Vector driver;
Vector port;
int resdialog;
/**
* Création du panel qui contientra tous les champs d'information pour la connexion.
* Attention, le dialogue n'est pas affiché. Il ne le sera que lorsque la méthode activate
* sera invoquée.
* @see #activate
*/
public ConnectionDialog(t_connect connexion) {
this.connexion = connexion;
Init();
}
public ConnectionDialog() {
Init();
}
public void activate() {
if (resdialog == 0) {
username = userNameField.getText();
password = passwordField.getText();
servername = serverNameField.getText();
port1 = (String) portField.getSelectedItem();
databaseName = databaseNameField.getText();
driver1 = (String) driverField.getSelectedItem();
server1 = (String) serverField.getSelectedItem();
if ( databaseName == null) {
text = "No database provided. Program stopped!";
bool = false;
//System.out.println("No database provided. Program stopped!");
System.exit(0);
}
try {
connexion = new t_connect(username,password,servername,port1,databaseName,driver1,server1);
//connexion = new t_connect(servername,username,password,databaseName); MYSQL
if ( ! connexion.acceptsConnection() ) {
text = "I'm not able to connect. Error:\n" + connexion.getError();
bool= false;
//System.out.println("I'm not able to connect. Error:\n" + connexion.getError());
} else {
text = "This DB accepts connection with these parameters!";
bool= true;
//System.out.println("This DB accepts connection with these parameters!");
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Classes du driver non trouvées","alert", JOptionPane.ERROR_MESSAGE);
}
}
}
public void setuserName(String username) {
this.username = username;
}
public String getuserName() {
return username;
}
public void setpassword(String password) {
this.password = password;
}
public String getpassword() {
return password;
}
public void setservername(String servername) {
this.servername = servername;
}
public String getservername() {
return servername;
}
public void setport(String port1) {
this.port1 = port1;
}
public String getport() {
return port1;
}
public void setdatabaseName(String databaseName) {
this.databaseName = databaseName;
}
public String getdatabaseName() {
return databaseName;
}
public void setdriver(String driver1) {
this.driver1 = driver1;
}
public String getdriver() {
return driver1;
}
public void setserver1(String server1) {
this.server1 = server1;
}
public String getserver1() {
return server1;
}
/**
* retourne l'url désignant la BD pour laquelle la connexion est établie.
* @return l'url désignant la bd
*/
public String getDBUrl() {
return (String) serverField.getSelectedItem();
}
} |
Partager