1 pièce(s) jointe(s)
Problème Vaadin - Connection à la base de données avec Wamp
Bonjour à tous,
Je suis un nouvel utilisateur de Vaadin (version 6) et j'ai de gros problèmes pour faire cohabiter Wamp (pour Mysql) et Tomcat.
J'ai changé le port pour le serveur Wamp, j'ai mis à la place du port 80 le port 82.
J'ai donc une classe nouveau qui contient la partie principale de mon code :
Code:
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
| package com.example.nouveau;
import com.example.nouveau.Mysql;
import com.vaadin.Application;
import com.vaadin.data.util.sqlcontainer.SQLContainer;
import com.vaadin.data.util.sqlcontainer.RowId;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PopupDateField;
import com.vaadin.ui.Slider;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
/**
* Main application class.
*/
public class NouveauApplication extends Application {
/**
*
*/
private static final long serialVersionUID = 1L;
private SQLContainer dossier;
private Window mainWindow;
private Table table;
private Panel panel_1;
private Panel panel_2;
private Slider slider_1;
private Slider slider_2;
private TabSheet tabSheet_1;
private PopupDateField popupDateField_1;
private VerticalLayout verticalLayout_1;
private VerticalLayout verticalLayout_2;
public NouveauApplication()
{
init();
}
@Override
public void init()
{
// building the main window
mainWindow = new Window("Vaadin_phonebook");
setMainWindow(mainWindow);
//main window = connexion page
//setMainWindow ( new LoginWindow() );
// connection to the MySQL database
Mysql mysql = new Mysql("jdbc:mysql://localhost:82/phpmyadmin/#PMAURL-1:db_structure.php?db=webavance_db&table=&server=1&target=&token=0497e64343f0942b88584e1c874c050c", "root", "");
// mapping with the table DOSSIER of the MySQL database
dossier = mysql.queryTable("dossier");
// creation of a table in the GUI
table = new Table("DOSSIER EN COURS", dossier);
table.setPageLength(20); // the number of rows per page
table.setHeight("250px");
table.setWidth("100%");
table.setImmediate(true); // the server is notify each time I select a row or modify values
table.setSelectable(true); // the user is allowed to select rows
table.setMultiSelect(false); // the user is not allowed to select more than one row
table.setEditable(true); // the user is allowed to modify values in the selected row
// layout of the main window
VerticalLayout vl = new VerticalLayout();
vl.setSpacing(true);
vl.setMargin(true);
mainWindow.setContent(vl);
// panel of action buttons
HorizontalLayout hl = new HorizontalLayout();
hl.setSpacing(true);
hl.setMargin(true);
//Button addButton = new Button("Add", dossier, "addItem"); // adds an empty row into the container and thus the table
//hl.addComponent(addButton);
Button validerButton = new Button("Validate", this, "validate");
hl.addComponent(validerButton);
Button deleteButton = new Button("Delete", this, "delete");
hl.addComponent(deleteButton);
// tabSheet_1
tabSheet_1 = new TabSheet();
tabSheet_1.setImmediate(false);
tabSheet_1.setSizeFull();
tabSheet_1.addComponent(table);
tabSheet_1.addComponent(panel_1);
// panel_1
panel_1 = buildPanel_1();
// panel_2
panel_2 = buildPanel_2();
vl.addComponent(tabSheet_1);
// placement of the buttons' panel and the table into the main window
vl.addComponent(hl);
}
private Panel buildPanel_1() {
// common part: create layout
panel_1 = new Panel();
panel_1.setCaption("NOUVEAU CREDIT");
panel_1.setImmediate(false);
panel_1.setWidth("100.0%");
panel_1.setHeight("100.0%");
// verticalLayout_1
verticalLayout_1 = new VerticalLayout();
verticalLayout_1.setImmediate(false);
verticalLayout_1.setWidth("100.0%");
verticalLayout_1.setHeight("100.0%");
verticalLayout_1.setMargin(false);
// verticalLayout_1
verticalLayout_1 = buildVerticalLayout_1();
panel_1.setContent(verticalLayout_1);
return panel_1;
}
private Panel buildPanel_2() {
// common part: create layout
panel_2 = new Panel();
panel_2.setCaption("NOUVEAU CLIENT");
panel_2.setImmediate(false);
panel_2.setWidth("100.0%");
panel_2.setHeight("100.0%");
// verticalLayout_2
//verticalLayout_2 = buildVerticalLayout_2();
panel_2.setContent(verticalLayout_2);
return panel_2;
}
private VerticalLayout buildVerticalLayout_1() {
// common part: create layout
verticalLayout_1 = new VerticalLayout();
verticalLayout_1.setImmediate(false);
verticalLayout_1.setWidth("100.0%");
verticalLayout_1.setHeight("100.0%");
verticalLayout_1.setMargin(false);
// Create a text field
TextField nomClient = new TextField("Nom du client");
verticalLayout_1.addComponent(nomClient);
TextField pClient = new TextField("Nom du client");
verticalLayout_1.addComponent(pClient);
// Create a selection component
ComboBox typeCredit = new ComboBox("Type de crédit");
verticalLayout_1.addComponent(typeCredit);
// Add items with given item IDs
typeCredit.setValue("Type de crédit");
typeCredit.addItem("Crédit automobile Ã* 3 %");
typeCredit.addItem("Crédit immobilier Ã* 20 %");
typeCredit.addItem("Crédit cuisine Ã* 70 %");
// slider_1
slider_1 = new Slider();
slider_1.setCaption("Montant du prêt");
slider_1.setImmediate(false);
slider_1.setWidth("160px");
slider_1.setHeight("14px");
verticalLayout_1.addComponent(slider_1);
// slider_2
slider_2 = new Slider();
slider_2.setCaption("Durée du prêt");
slider_2.setImmediate(false);
slider_2.setWidth("160px");
slider_2.setHeight("14px");
verticalLayout_1.addComponent(slider_2);
// popupDateField_1
popupDateField_1 = new PopupDateField();
popupDateField_1.setCaption("Date de début");
popupDateField_1.setImmediate(false);
popupDateField_1.setWidth("-1px");
popupDateField_1.setHeight("-1px");
verticalLayout_1.addComponent(popupDateField_1);
Button addForm = new Button("Valider", dossier, "addItem");
verticalLayout_1.addComponent(addForm);
return verticalLayout_1;
}
// validate an update of the container into the database
public void validate()
{
try {
dossier.commit();
mainWindow.showNotification("SUCCESS", "Transaction successfull", Window.Notification.TYPE_HUMANIZED_MESSAGE);
} catch (Exception e) {
mainWindow.showNotification("ERROR", e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
}
}
// delete a record
public void delete()
{
RowId itemID = (RowId) table.getValue(); // retrieves the id of the record
if (itemID != null) {
dossier.removeItem(itemID); // remove the record from the container
validate(); // perform the update into the database
}
}
} |
et une classe Mysql pour la partie connexion à Mysql :
Code:
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
| package com.example.nouveau;
import java.sql.SQLException;
import com.vaadin.data.util.sqlcontainer.SQLContainer;
import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool;
import com.vaadin.data.util.sqlcontainer.query.FreeformQuery;
import com.vaadin.data.util.sqlcontainer.query.TableQuery;
import com.vaadin.data.util.sqlcontainer.query.generator.DefaultSQLGenerator ;
public class Mysql {
private SimpleJDBCConnectionPool connectionPool;
private DefaultSQLGenerator generator;
public Mysql(String server, String user, String pwd){
try {
connectionPool = new SimpleJDBCConnectionPool(
"com.mysql.jdbc.Driver",
server, user, pwd, 2, 2);
System.out.println("connection pool created for Mysql on " + server);
} catch (SQLException e) {
// Handle error
e.printStackTrace();
}
generator = new DefaultSQLGenerator("`", "`");
}
public SQLContainer queryTable(String tableName){
SQLContainer container = null;
try
{
TableQuery tq = new TableQuery(tableName, connectionPool, generator);
container = new SQLContainer(tq);
System.out.println("container created for table " + tableName);
}
catch (SQLException c) {
System.err.println("Base de données non trouvée ou requête incorrecte");
}
return container;
}
public SQLContainer dataView(String viewName)
{
SQLContainer container = null;
try
{
FreeformQuery tq = new FreeformQuery("select * from " + viewName, connectionPool);
container = new SQLContainer(tq);
System.out.println("container created for view " + viewName);
} catch (SQLException e) {
e.printStackTrace();
}
return container;
}
} |
Mais voilà quand je lance mon application, j'obtiens ce type d'erreur :
Pièce jointe 149391
Quelqu'un aurait t-il une idée de la source de cette erreur, et pourrai m'éclairer sur la configuration à adopter pour se connecter à Wamp pour Mysql en lançant une application avec un serveur Tomcat. Je ne sais pas si l'erreur vient de mon code ou de la configuration de mes outils.
Merci d'avance,