Vidage JTABLE avec DEFAULTTABLEMODEL [Résolu]

tomski 48 Messages postés mercredi 24 mars 2004Date d'inscription 24 décembre 2009 Dernière intervention - 13 août 2009 à 18:09 - Dernière réponse : tomski 48 Messages postés mercredi 24 mars 2004Date d'inscription 24 décembre 2009 Dernière intervention
- 20 août 2009 à 09:16
salut a tous,


jarrive pas a vider ma jtable!
jai tout essaye le setRowCount(0), le fire***, le getVectorData, le removeAllElements....

please help, jy pige rien, quand je rafraichis ma jtable ca garde a laffichage les resultats des precedentes requetes et rajoute le resulat de la nouvelle requete. je voudrais juste le resultat de la nouvelle requete biensur (la requete se fait en selectionnant les listes et en renseignant les dates), apres c du sql classic et la requette focntionne, c juste le refersh de la table (le clear()) qui bug.


kelkun peut il maider? ce serait magnifique!

davance MERCI :)


ci dessous le code:
>>>voir la fonction clear();





import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.Graphics.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.Properties;
import java.util.*;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.Writer;
import java.math.*;
import javax.imageio.*;
import javax.imageio.stream.FileImageOutputStream;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.awt.image.DataBufferByte;
import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.awt.image.DataBufferByte;
import javax.imageio.ImageIO;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
import java.security.*;
import java.security.spec.*;
import java.math.*;
import javax.imageio.*;
import javax.imageio.stream.FileImageOutputStream;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.*;
import java.util.regex.Pattern;
import java.net.URL.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.*;
/*
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.*;
import javax.swing.RowFilter;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
*/
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import java.util.Vector;


/*
* Interface graphique = OK
* Requete simple = OK
* Stocker nom columns dans un array de string => OK
* Stocker resultat comparaison (linkage) de table dans une String
* Compiler toute la query dans une String => almost OK
* Afficher resultat requete dans une JTable => OK
* Exporter le contenu de la JTable dans Excel => OK
* requete speciale pour SAM pour la facturation
*
*
*
*
*/


public class E extends JFrame{


Dialog d1, d2;
JButton OKBTN, OKexport, smBTN, bckBTN;
JLabel lbChamps;
JLabel lbDateDEB;
JLabel lbDateFIN;
JLabel lbUI;
JLabel lbSociete;
JLabel lbGTR;
JTextField txt_DEB;
JTextField txt_FIN;
JList lst1;
JList lstUI;
JList lstSociete;
JList lstGTR;
JScrollPane scroll1;
JScrollPane scroll2;
JScrollPane scroll3;
JScrollPane scroll4;

String DateDEB, DateFIN;

static String[] arrayString= {"Tous","3", "4","5","6", "7","8","9","10", "12", "P"};
static String[] arrayUI= {"Tous","PI7", "PI9","SE7", "SI9", "SO7","RI7","BNI","BGI"};
static String[] arraySociete= {"Tous","ABDC", "AS-COM","SFTA", "WELLCOM"};
static String[] arrayGTR= {"Tous","4H0", "8H0","4HN0","8HN0","24H0","24HN0","J1H0", "J2H0"};
static String[] cols= {"Tous","4h0", "8h0","J1h0", "J2h0"};
String[] str = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
String query= "";
String endquery = " Order by RDV,GTR,planifie,ot.code_codeot";

Statement stmt = null;
ResultSet rs = null;
Connection connexion;

FileWriter flog;
BufferedWriter out;

String[] headers;
int colNo;
JTable tb= new JTable();
ResultSetMetaData meta, rsmd;
Object[] objects;
DefaultTableModel MonModel;
String societe, ui, etat, gtr;
String elements[];
boolean sm false; //exportSAM? false



public E(){
JLabel lbfrm = new JLabel();
System.out.println("in E()");
try {
URL helpURL=E.class.getResource("E.htm");
System.out.println(helpURL);
//JEditorPane ep = new JEditorPane(new URL(CINTEL.class.getResource("/CINTEL.html")));
JEditorPane ep = new JEditorPane(helpURL);
//this.getClass().getResource("/resource/buttons1.png")
this.getContentPane().add(ep, BorderLayout.PAGE_START);
}catch(Exception e){
System.out.println(e);
}

JPanel pstr= new JPanel();
String myString = new String();
myString= str[12].toUpperCase()+str[0]+str[3]+str[4]+ " " +str[1]+str[24]+ " "+str[9].toUpperCase()+str[20]+str[11]+
str[8]+str[4]+ " "+str[1].toUpperCase()+str[17]+str[20]+str[13]+str[8]+str[0]+str[18]+ " "+
str[0].toUpperCase()+str[11]+str[11]+ " "+str[17].toUpperCase()+str[8]+str[6]+str[7]+str[19]+str[18]+ " "+
str[17].toUpperCase()+str[4]+str[18]+str[4]+str[17]+str[21]+str[4]+str[3];
JLabel lb = new JLabel(myString);
pstr.add(lb);


this.getContentPane().add(pstr, BorderLayout.PAGE_END);
//this.pack;
this.setSize(600,620);
this.setTitle("EXPORT REQUETE SQL");
ImageIcon img= new ImageIcon("logo.bmp");

this.setIconImage(img.getImage());
this.setVisible(true);
showDialog1();

}//end E()

public static void main(String[] args){
E ex = new E();
ex.getContentPane().add(new MyComponent());
ex.setDefaultCloseOperation(EXIT_ON_CLOSE);
//cintel.add(editorPane);
ex.setVisible(true);
//showDialog1();

}



public void showDialog1(){

lst1 = new JList(arrayString);
lstUI = new JList(arrayUI);
lstSociete = new JList(arraySociete);
lstGTR = new JList(arrayGTR);

scroll1 = new JScrollPane(lst1);
scroll2 = new JScrollPane(lstUI);
scroll3 = new JScrollPane(lstSociete);
scroll4 = new JScrollPane(lstGTR);

lst1.setVisibleRowCount(4);
lstUI.setVisibleRowCount(4);
lstSociete.setVisibleRowCount(4);
lstGTR.setVisibleRowCount(4);

tb = new JTable();

/********************************** Choix des ETATS ***********************************************/
ListSelectionListener lst1_listener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent listSelectionEvent) {
Object selectedLST1Values[] = lst1.getSelectedValues();
int selectionsLST1[] = lst1.getSelectedIndices();
//debut de chaine "etat"
// etat = new String();
etat = " (";
//ensuite on boucle pour concatener la requete sur les etats
for (int n = 0; n < selectionsLST1.length; n++) {
System.out.println("selectionsLST1.length= " + selectionsLST1.length);

switch(selectionsLST1[n]){
case 0: etat "" ;break;//Tous> do nothing
case 1: etat etat + "etat_ot.codeetatot'3';" ;break;
case 2: etat = etat + "etat_ot.codeetatot='4';" ;break;
case 3: etat etat + "etat_ot.codeetatot'5';" ;break;
case 4: etat etat + "etat_ot.codeetatot'6';" ;break;
case 5: etat etat + "etat_ot.codeetatot'7';" ;break;
case 6: etat etat + "etat_ot.codeetatot'8';" ;break;
case 7: etat etat + "etat_ot.codeetatot'9';" ;break;
case 8: etat etat + "etat_ot.codeetatot'10';" ;break;
case 9: etat etat + "etat_ot.codeetatot'12';" ;break;
case 10: etat etat + "etat_ot.codeetatot'P';" ;break;
default: etat = "";break;//default "Tous"
}//end switch

//juste pour vérifier
System.out.println(selectionsLST1[n] + "/" + selectedLST1Values[n] + " ");
}//end for
if (selectionsLST1[0] == 0){
//si on selectionne Tous (indice 0),ne rien faire
//car pas besoin de preciser, la requete prendra tous par defaut
etat ="";
}else{
//autrement, on termine la chaine par ')'
etat = etat + ")";
}//end if
//on print le resultat final de la requete
System.out.println("ETAT FINI = "+etat);

//parse la string pour detecter les espaces et remplacer par des "OR"
//on split la string, tous ce qui est inclus entre ';' sera stocker dans array Elements
elements =etat.split(";");
System.out.println("selectionsLST1.length = " + selectionsLST1.length);
//String de manipulation et de stockage
String stock="";
String s="";

for (int i = 0; i< elements.length; i++){
if (i == elements.length-2){
System.out.println("i elements.length-2 || i "+i);
s = s + elements[i];
stock =s;
System.out.println("in i == elements.length-2 >>>> s= "+s);
}else if (i == elements.length-1) {
s = s + elements[i];
stock =s;
System.out.println("else if i == elements.length-1 >>>> s= "+s);
}else{
s = s + elements[i] + " OR " ;
stock =s;
System.out.println("else >>>> s= "+s);
}//end if
}//end for
//une toute derniere verification
System.out.println("stock = "+stock);
if (selectionsLST1[0] == 0){
//si on selectionne Tous (indice 0),ne rien faire
//car pas besoin de preciser, la requete prendra tous par defaut
etat ="";
}else{
etat=stock;
}//end if
//etat =stock;
}//end public void
};


/********************************** Choix des UI ***********************************************/
ListSelectionListener lstUI_listener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent listSelectionEvent) {
Object selectedLSTUIValues[] = lstUI.getSelectedValues();
int selectionsLSTUI[] = lstUI.getSelectedIndices();
//debut de chaine "ui"
ui = " (";
//ensuite on boucle pour concatener la requete sur les etats
for (int n = 0; n < selectionsLSTUI.length; n++) {
System.out.println("selectionsLSTUI.length= " + selectionsLSTUI.length);

switch(selectionsLSTUI[n]){
case 0: ui "" ;break;//Tous> do nothing
case 1: ui ui + "OT.UI'PI7';" ;break;//
case 2: ui ui + "OT.UI'PI9';" ;break;//"ASCOM"
case 3: ui ui + "OT.UI'SE7';";break;
case 4: ui ui + "OT.UI'SI9';" ;break;
case 5: ui ui + "OT.UI'SO7';" ;break;
case 6: ui ui + "OT.UI'RI7';" ;break;
case 7: ui ui + "OT.UI'BNI';" ;break;
case 8: ui ui + "OT.UI'BGI';" ;break;
case 9: ui ui + "OT.UI'RI7';" ;break;
default: ui = "";break;//default "Tous"
}//end switch
//juste pour vérifier
System.out.println(selectionsLSTUI[n] + "/" + selectedLSTUIValues[n] + " ");
}//end for
if (selectionsLSTUI[0] == 0){
//si on selectionne Tous (indice 0),ne rien faire
//car pas besoin de preciser, la requete prendra tous par defaut
ui ="";
}else{
//autrement, on termine la chaine par ')'
ui = ui + ")";
}
//on print le resultat final de la requete
System.out.println("UI FINI = "+ui);

//parse la string pour detecter les espaces et remplacer par des "OR"
//on split la string, tous ce qui est inclus entre ';' sera stocker dans array Elements
elements =ui.split(";");
System.out.println("selectionsLSTUI.length = " + selectionsLSTUI.length);
//String de manipulation et de stockage
String stock="";
String s="";

for (int i = 0; i< elements.length; i++){
if (i == elements.length-2){
System.out.println("i elements.length-2 || i "+i);
s = s + elements[i];
stock =s;
System.out.println("in i == elements.length-2 >>>> s= "+s);
}else if (i == elements.length-1) {
s = s + elements[i];
stock =s;
System.out.println("else if i == elements.length-1 >>>> s= "+s);
}else{
s = s + elements[i] + " OR " ;
stock =s;
System.out.println("else >>>> s= "+s);
}
}//end for
//une toute derniere verification
System.out.println("stock = "+stock);
if (selectionsLSTUI[0] == 0){
//si on selectionne Tous (indice 0),ne rien faire
//car pas besoin de preciser, la requete prendra tous par defaut
ui ="";
}else{
ui=stock;
}//end if
}//end public void
};


/********************************** Choix des GTR ***********************************************/
/*
ListSelectionListener lstGTR_listener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent listSelectionEvent) {
Object selectedLSTGTRValues[] = lstGTR.getSelectedValues();
int selectionsLSTGTR[] = lstGTR.getSelectedIndices();
//debut de chaine "gtr"
gtr = " (";
//ensuite on boucle pour concatener la requete sur les etats
for (int n = 0; n < selectionsLSTGTR.length; n++) {
System.out.println("selectionsLSTGTR.length= " + selectionsLSTGTR.length);

switch(selectionsLSTGTR[n]){

case 0: gtr "" ;break;//Tous> do nothing
case 1: gtr gtr + "Engagement.LibelleEngagement'4H0';" ;break;//
case 2: gtr gtr + "Engagement.LibelleEngagement'8H0';" ;break;//"ASCOM"
case 3: gtr gtr + "Engagement.LibelleEngagement'4HN0';";break;
case 4: gtr gtr + "Engagement.LibelleEngagement'8HN0';" ;break;
case 5: gtr gtr + "Engagement.LibelleEngagement'24H0';" ;break;
case 6: gtr gtr + "Engagement.LibelleEngagement'24HN0';" ;break;
case 7: gtr gtr + "Engagement.LibelleEngagement'J1H0';" ;break;
case 8: gtr gtr + "Engagement.LibelleEngagement'J2H0';" ;break;
//case 9: gtr gtr + "Engagement.LibelleEngagement'4h0';" ;break;
default: gtr = "";break;//default "Tous"

}//end switch
//juste pour vérifier
System.out.println(selectionsLSTGTR[n] + "/" + selectedLSTGTRValues[n] + " ");
}//end for
if (selectionsLSTGTR[0] == 0){
//si on selectionne Tous (indice 0),ne rien faire
//car pas besoin de preciser, la requete prendra tous par defaut
gtr ="";
}else{
//autrement, on termine la chaine par ')'
gtr = gtr + ")";
}
//on print le resultat final de la requete
System.out.println("UI FINI = "+ui);

//parse la string pour detecter les espaces et remplacer par des "OR"
//on split la string, tous ce qui est inclus entre ';' sera stocker dans array Elements
elements =gtr.split(";");
System.out.println("selectionsLSTGTR.length = " + selectionsLSTGTR.length);
//String de manipulation et de stockage
String stock="";
String s="";

for (int i = 0; i< elements.length; i++){
if (i == elements.length-2){
System.out.println("i elements.length-2 || i "+i);
s = s + elements[i];
stock =s;
System.out.println("in i == elements.length-2 >>>> s= "+s);
}else if (i == elements.length-1) {
s = s + elements[i];
stock =s;
System.out.println("else if i == elements.length-1 >>>> s= "+s);
}else{
s = s + elements[i] + " OR " ;
stock =s;
System.out.println("else >>>> s= "+s);
}
}//end for
//une toute derniere verification
System.out.println("stock = "+stock);
if (selectionsLSTGTR[0] == 0){
//si on selectionne Tous (indice 0),ne rien faire
//car pas besoin de preciser, la requete prendra tous par defaut
gtr ="";
}else{gtr=stock;
}//end if
}//end public void
};
*/

/********************************** Choix de la societe ***********************************************/
ListSelectionListener lstSociete_listener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent listSelectionEvent) {
Object selectedLSTSOCIETEValues[] = lstSociete.getSelectedValues();
int selectionsLSTSOCIETE[] = lstSociete.getSelectedIndices();
//debut de chaine "societe"
societe = " (";

//ensuite on boucle pour concatener la requete sur les Divisions de Production
for (int n = 0; n < selectionsLSTSOCIETE.length; n++) {
switch(selectionsLSTSOCIETE[n]){
case 0: societe "" ;break;//Tous> do nothing
case 1: societe societe + "DivProd.nomdivisionproduction 'ABDC';" ;break;//
case 2: societe societe + "DivProd.nomdivisionproduction 'AS-COM';" ;break;//"ASCOM"
case 3: societe societe + "DivProd.nomdivisionproduction 'SFTA';";break;
case 4: societe societe + "DivProd.nomdivisionproduction 'WELLCOM';" ;break;
default: societe = "";break;//default "Tous"

}//end switch
//juste pour vérifier
System.out.println(selectionsLSTSOCIETE[n] + "/" + selectedLSTSOCIETEValues[n] + " ");
}//end for
if (selectionsLSTSOCIETE[0] == 0){
//si on selectionne Tous (indice 0),ne rien faire
//car pas besoin de preciser, la requete prendra tous par defaut
societe ="";
}else{
//autrement, on termine la chaine par ')'
societe = societe + ")";
}
//on print le resultat final de la requete
System.out.println("SOCIETE FINI = "+societe);

//parse la string pour detecter les espaces et remplacer par des "OR"
//on split la string, tous ce qui est inclus entre ';' sera stocker dans array Elements
elements =societe.split(";");
System.out.println("selectionsLSTSOCIETE.length = " + selectionsLSTSOCIETE.length);
//String de manipulation et de stockage
String stock="";
String s="";

for (int i = 0; i< elements.length; i++){
if (i == elements.length-2){
System.out.println("i elements.length-2 || i "+i);
s = s + elements[i];
stock =s;
System.out.println("in i == elements.length-2 >>>> s= "+s);
}else if (i == elements.length-1) {
s = s + elements[i];
stock =s;
System.out.println("else if i == elements.length-1 >>>> s= "+s);
}else{
s = s + elements[i] + " OR " ;
stock =s;
System.out.println("else >>>> s= "+s);
}
}//end for

//une toute derniere verification
System.out.println("stock = "+stock);
if (selectionsLSTSOCIETE[0] == 0){
//si on selectionne Tous (indice 0),ne rien faire
//car pas besoin de preciser, la requete prendra tous par defaut
societe ="";
}else{
societe=stock;
}//end if
}//end public void
};



lst1.addListSelectionListener(lst1_listener);
lstUI.addListSelectionListener(lstUI_listener);
lstSociete.addListSelectionListener(lstSociete_listener);
// lstGTR.addListSelectionListener(lstGTR_listener);

scroll1.setPreferredSize(new Dimension(100, 80));
scroll2.setPreferredSize(new Dimension(100, 80));
scroll3.setPreferredSize(new Dimension(100, 80));
// scroll4.setPreferredSize(new Dimension(100, 80));


d1 = new JDialog(this, "Choix des colonnes...", true);
OKBTN = new JButton("OK");
OKBTN.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("in OK");
DateDEB = txt_DEB.getText();
DateFIN = txt_FIN.getText();
//System.out.println("DateDEB= " + DateDEB);
//System.out.println("DateFIN= "+ DateFIN);
//recup des objets selectionnés dans les listes
connectDB();

}
});

smBTN = new JButton("Export SAM");
smBTN.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("in EXPORT SAM");
DateDEB = txt_DEB.getText();
DateFIN = txt_FIN.getText();
//recup des objets selectionnés dans les listes
sm = true; //oui on a bien clique sur EXPORTSAM
connectDB();

}
});
bckBTN = new JButton("Go Back");
bckBTN.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("in BACK");
d2.setVisible(false);
d1.setVisible(true);
/****TEST SI DEJA LANCE QUERY*****/
MonModel = (DefaultTableModel) tb.getModel();
if (query != null || query != ""){
query = "";
//deleteTable(MonModel);
clear();
//Suppr();
}else{
System.out.println("HERE ELSE QUERY == ??? >>>" + query);
}//end if
//deleteTable(MonModel);


}
});






JPanel lstPanel= new JPanel();
JPanel goPanel = new JPanel();
JPanel pstr= new JPanel();
String myString = new String();
myString= str[12].toUpperCase()+str[0]+str[3]+str[4]+ " " +str[1]+str[24]+ " "+str[9].toUpperCase()+str[20]+str[11]+
str[8]+str[4]+ " "+str[1].toUpperCase()+str[17]+str[20]+str[13]+str[8]+str[0]+str[18]+ " "+
str[0].toUpperCase()+str[11]+str[11]+ " "+str[17].toUpperCase()+str[8]+str[6]+str[7]+str[19]+str[18]+ " "+
str[17].toUpperCase()+str[4]+str[18]+str[4]+str[17]+str[21]+str[4]+str[3];
JLabel lb = new JLabel(myString);
pstr.add("South", lb);
JPanel choix1Panel = new JPanel();
JPanel choixLogPanel = new JPanel();

txt_DEB = new JTextField(10);
txt_FIN = new JTextField(10);

txt_DEB.setToolTipText("Date Format : YYYY-MM-DD");
txt_FIN.setToolTipText("Date Format : YYYY-MM-DD");
OKBTN.setToolTipText("Click to launch Query");
smBTN.setToolTipText("Click to launch SAM Query for Billing Purpose");

lbChamps = new JLabel("Etats");
lbDateDEB = new JLabel("Date Début");
lbDateFIN = new JLabel("Date Fin");
lbUI = new JLabel("UI");
lbSociete = new JLabel("Société");
// lbGTR = new JLabel("GTR");

GridLayout grid1 = new GridLayout(2,4,10,10);
GridLayout grid2 = new GridLayout(2,4,10,00);
GridLayout grid3 = new GridLayout(1,2,10,00);

JPanel pdate = new JPanel();
JPanel plist = new JPanel();
JPanel p = new JPanel();
pdate.setLayout(grid1);
plist.setLayout(grid2);

pdate.add(lbDateDEB);
pdate.add(lbDateFIN);
pdate.add(txt_DEB);
pdate.add(txt_FIN);

plist.add(lbChamps);
plist.add(lbUI);
plist.add(lbSociete);
plist.add(scroll1);
plist.add(scroll2);
plist.add(scroll3);
p.add("North", pdate);
p.add("South", plist);

goPanel.add("North", OKBTN);
goPanel.add("South", smBTN );

JPanel ptotal = new JPanel();
ptotal.add("North", p);
ptotal.setLayout(grid3);


d1.add(ptotal, BorderLayout.CENTER);
d1.add(pstr, BorderLayout.PAGE_END);
d1.add(goPanel, BorderLayout.LINE_END);
d1.setSize(700,350);
d1.setVisible(true);

}//end showDialog1


public void connectDB(){

//Connection connection = null;
try {
System.out.println("Trying to connect to MYSQL...");
// Load the JDBC driver
String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);

// Create a connection to the database

String serverName = "10.27.202.1:23516"; //10.27.202.1:23516
String mydatabase = "snms";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "ineo";
String password = "ineo01";
System.out.println("URL = "+url);
connexion= DriverManager.getConnection(url, username, password);
System.out.println("connexion = "+ connexion.toString());

//TEST REQUETE
try {

// stmt = connexion.createStatement();
stmt = connexion.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);


/* Execute the query */
//rs stmt.executeQuery("SELECT * FROM action where CODEACTIONOT 10");
//Get general information about DB
DatabaseMetaData mtdt = connexion.getMetaData();
System.out.println("URL in use: " + mtdt.getURL());
System.out.println("User name: " + mtdt.getUserName());
System.out.println("DBMS name: " + mtdt.getDatabaseProductName());
System.out.println("DBMS version: " + mtdt.getDatabaseProductVersion());
System.out.println("Driver name: " + mtdt.getDriverName());
System.out.println("Driver version: " + mtdt.getDriverVersion());
//End Get general information about DB


System.out.println("societe"+ societe + " / etat "+etat);

//Here is the Query (direct from mySQL)

/*
query"select ot.code_codeot,etat_ot.codeetatot etat, OT.CodeActivite AS Activite, OT.CodeProduit AS Produit,(Select ifNull((Select LibelleEngagement From Engagement E2 Where E2.EngagementID OT.EngagementID), ' ')) AS GTR, OT.UI UI, LI.ND AS ND, ifNull(OT.OrigineSignalisation,' ') AS Origine,(Select ifNull((Select OT2.rendezvous From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS RDV,(Select ifNull((Select AD2.LibelleCommune From Ligne L2 Join Adresse AD2 On L2.EquipementID = AD2.EquipementID Where L2.LigneID = LI.LigneID), ' ')) AS Lieu,(select ifnull((select if(nom_utilisateur='',nom_titulaire,nom_utilisateur)from abonne AB where AB.equipementid=LI.equipementid ),' ')) as abonne, EQ.LibelleEquipe AS Equipe, DivProd.nomdivisionproduction as Societe,(Select ifNull((Select Date(OT2.DateHeureRdvEffectif)From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS planifie,(Select ifNull((Select OT2.DateHeureContractuelle From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS DateHeureContractuelle,(Select ifNull((Select Date(OT2.DateHeureTest) From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS debut,(Select ifNull((Select Date(OT2.DateHeureCloture) From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS Fin,(Select ifNull((Select RI2.CodeResultatIntervention From Asso_Ligne_Resultat_Intervention ALRI2 Join Resultat_Intervention RI2 On ALRI2.ResultatInterventionID = RI2.ResultatInterventionID Where ALRI2.LigneID = LI.LigneID), ' ')) AS Resultat_Intervention,(Select ifNull((Select ER2.LibelleEssaiRobot From Asso_Ligne_Resultat_Intervention ALRI2 Join Essai_Robot ER2 On ALRI2.EssaiRobotID = ER2.EssaiRobotID Where ALRI2.LigneID = LI.LigneID), ' ')) AS Essais, (Select if(OT2.Facture is Null or OT2.Facture = 0, 'N', 'O') From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT ) AS Facturation,(Select ifNull((Select sum(NA.QuantiteAction) From Necessiter_Action NA Where NA.LigneID = LI.LigneID And NA.CodeActionOT = 20), ' ')) AS Pose_DTI,(Select ifNull((Group_Concat((Select (if((MU2.AncTete Like '%%%-%%-%%%'), Concat(MU2.AncTete, '\n', 'N DECH ', MU2.CodeDecharge), Concat(MU2.NouvTete, '/', MU2.NouvAmorce, '/', MU2.NouvPaire, '\n', 'N DECH ', MU2.CodeDecharge))) From Mutation MU2 Where MU2.MutationID = ALM.MutationID) SEPARATOR '\n')), ' ') From Ligne LI2 Left Join Asso_Ligne_Mutation ALM On LI2.LigneID = ALM.LigneID Where LI2.LigneID = LI.LigneID ) AS New_Const_Comment, OT.CommentaireInterne AS Comment,(select ifnull((select pc.codecategoriepc from asso_ligne_architecture,pc where asso_ligne_architecture.equipementid=pc.equipementid and asso_ligne_architecture.ligneid=LI.ligneid),' ')) AS CategoriePC,(select ifnull((select libellequalificatif from qualifie_OT join qualificatif on ( qualificatif.codequalificatif=qualifie_OT.codequalificatif) where (qualificatif.codequalificatif=5 or qualificatif.codequalificatif=6) and qualifie_OT.code_codeot=ot.code_codeot),' ')) as Travail,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BRA' And ALA2.LigneID = LI.LigneID), '')) AS BRA,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BRI' And ALA2.LigneID = LI.LigneID), '')) AS BRI, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BRF' And ALA2.LigneID = LI.LigneID), '')) AS BRF, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BRS' And ALA2.LigneID = LI.LigneID), '')) AS BRS,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'ZERO' And ALA2.LigneID = LI.LigneID), '')) AS ZERO,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'MIT' And ALA2.LigneID = LI.LigneID), '')) AS MIT, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'PDF' And ALA2.LigneID = LI.LigneID), '')) AS PDF,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'RDS' And ALA2.LigneID = LI.LigneID), '')) AS RDS, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'RSTH' And ALA2.LigneID = LI.LigneID), '')) AS RSTH, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BSR' And ALA2.LigneID = LI.LigneID), '')) AS BSR,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'JRT' And ALA2.LigneID = LI.LigneID), '')) AS JRT, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'JRTM' And ALA2.LigneID = LI.LigneID), '')) AS JRTM, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'RNU' And ALA2.LigneID = LI.LigneID), '')) AS RNU, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'HIC' And ALA2.LigneID = LI.LigneID), '')) AS HIC, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'GTR' And ALA2.LigneID = LI.LigneID), '')) AS gtr, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'LAN' And ALA2.LigneID = LI.LigneID), '')) AS LAN, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'NET' And ALA2.LigneID = LI.LigneID), '')) AS NET, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'PCM' And ALA2.LigneID = LI.LigneID), '')) AS PCM, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'RDM' And ALA2.LigneID = LI.LigneID), '')) AS RDM, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'AMS' And ALA2.LigneID = LI.LigneID), '')) AS AMS, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'MPSR' And ALA2.LigneID = LI.LigneID), '')) AS MPSR, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'MPREJ' And ALA2.LigneID = LI.LigneID), '')) AS MPREJ, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'MPREN' And ALA2.LigneID = LI.LigneID), '')) AS MPREN, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'PCX' And ALA2.LigneID = LI.LigneID), '')) AS PCX from code_ot ot Join Asso_OT_ND AON On OT.Code_CodeOT = AON.Code_CodeOT Join Ligne LI On AON.LigneID = LI.LigneID Left Join Adresse AD On LI.EquipementID = AD.EquipementID Left Join Asso_Ligne_Resultat_Intervention ALRI On LI.LigneID = ALRI.LigneID Left Join Resultat_Intervention RI On ALRI.ResultatInterventionID = RI.ResultatInterventionID Left Join Essai_Robot ER On ALRI.EssaiRobotID = ER.EssaiRobotID left Join OT_EQP_Planning OEP On OT.Code_CodeOT = OEP.Code_CodeOT left Join Equipe EQ On OEP.CodeEquipe = EQ.CodeEquipe left join DivProd DivProd on (divprod.codedivisionproduction=EQ.codedivisionproduction) join etat_OT on (ot.etatotid=etat_ot.etatotid) where Date(OT.DateHeureContractuelle) >= '"+DateDEB+"' And Date(OT.DateHeureContractuelle) <= '"+DateFIN+"' Order by RDV,GTR,planifie,ot.code_codeot
*/

/****TEST SI DEJA LANCE QUERY*****/
/*
if (query != null || query != ""){
query = "";
deleteTable(MonModel);
}else{
System.out.println("HERE ELSE QUERY == ??? >>>" + query);
}*/

//And here is the query with "DateDEB" and "DateFIN" parameters
query "select ot.code_codeot,etat_ot.codeetatot etat, OT.CodeActivite AS Activite, OT.CodeProduit AS Produit,(Select ifNull((Select LibelleEngagement From Engagement E2 Where E2.EngagementID OT.EngagementID), ' ')) AS GTR, OT.UI UI, LI.ND AS ND, ifNull(OT.OrigineSignalisation,' ') AS Origine,(Select ifNull((Select OT2.rendezvous From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS RDV,(Select ifNull((Select AD2.LibelleCommune From Ligne L2 Join Adresse AD2 On L2.EquipementID = AD2.EquipementID Where L2.LigneID = LI.LigneID), ' ')) AS Lieu,(select ifnull((select if(nom_utilisateur='',nom_titulaire,nom_utilisateur)from abonne AB where AB.equipementid=LI.equipementid ),' ')) as abonne, EQ.LibelleEquipe AS Equipe, DivProd.nomdivisionproduction as Societe,(Select ifNull((Select Date(OT2.DateHeureRdvEffectif)From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS planifie,(Select ifNull((Select OT2.DateHeureContractuelle From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS DateHeureContractuelle,(Select ifNull((Select Date(OT2.DateHeureTest) From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS debut,(Select ifNull((Select Date(OT2.DateHeureCloture) From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT),' ')) AS Fin,(Select ifNull((Select RI2.CodeResultatIntervention From Asso_Ligne_Resultat_Intervention ALRI2 Join Resultat_Intervention RI2 On ALRI2.ResultatInterventionID = RI2.ResultatInterventionID Where ALRI2.LigneID = LI.LigneID), ' ')) AS Resultat_Intervention,(Select ifNull((Select ER2.LibelleEssaiRobot From Asso_Ligne_Resultat_Intervention ALRI2 Join Essai_Robot ER2 On ALRI2.EssaiRobotID = ER2.EssaiRobotID Where ALRI2.LigneID = LI.LigneID), ' ')) AS Essais, (Select if(OT2.Facture is Null or OT2.Facture = 0, 'N', 'O') From Code_OT OT2 Where OT2.Code_CodeOT = OT.Code_CodeOT ) AS Facturation,(Select ifNull((Select sum(NA.QuantiteAction) From Necessiter_Action NA Where NA.LigneID = LI.LigneID And NA.CodeActionOT = 20), ' ')) AS Pose_DTI,(Select ifNull((Group_Concat((Select (if((MU2.AncTete Like '%%%-%%-%%%'), Concat(MU2.AncTete, '\n', 'N DECH ', MU2.CodeDecharge), Concat(MU2.NouvTete, '/', MU2.NouvAmorce, '/', MU2.NouvPaire, '\n', 'N DECH ', MU2.CodeDecharge))) From Mutation MU2 Where MU2.MutationID = ALM.MutationID) SEPARATOR '\n')), ' ') From Ligne LI2 Left Join Asso_Ligne_Mutation ALM On LI2.LigneID = ALM.LigneID Where LI2.LigneID = LI.LigneID ) AS New_Const_Comment, OT.CommentaireInterne AS Comment,(select ifnull(( select pc.codecategoriepc from asso_ligne_architecture,pc where asso_ligne_architecture.equipementid=pc.equipementid and asso_ligne_architecture.ligneid=LI.ligneid),' ')) AS CategoriePC,(select ifnull((select libellequalificatif from qualifie_OT join qualificatif on ( qualificatif.codequalificatif=qualifie_OT.codequalificatif) where (qualificatif.codequalificatif=5 or qualificatif.codequalificatif=6) and qualifie_OT.code_codeot=ot.code_codeot),' ')) as Travail,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BRA' And ALA2.LigneID = LI.LigneID), '')) AS BRA,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BRI' And ALA2.LigneID = LI.LigneID), '')) AS BRI, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BRF' And ALA2.LigneID = LI.LigneID), '')) AS BRF, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BRS' And ALA2.LigneID = LI.LigneID), '')) AS BRS,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'ZERO' And ALA2.LigneID = LI.LigneID), '')) AS ZERO,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'MIT' And ALA2.LigneID = LI.LigneID), '')) AS MIT, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'PDF' And ALA2.LigneID = LI.LigneID), '')) AS PDF,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'RDS' And ALA2.LigneID = LI.LigneID), '')) AS RDS, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'RSTH' And ALA2.LigneID = LI.LigneID), '')) AS RSTH, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'BSR' And ALA2.LigneID = LI.LigneID), '')) AS BSR,(Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'JRT' And ALA2.LigneID = LI.LigneID), '')) AS JRT, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'JRTM' And ALA2.LigneID = LI.LigneID), '')) AS JRTM, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'RNU' And ALA2.LigneID = LI.LigneID), '')) AS RNU, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'HIC' And ALA2.LigneID = LI.LigneID), '')) AS HIC, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'GTR' And ALA2.LigneID = LI.LigneID), '')) AS gtr, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'LAN' And ALA2.LigneID = LI.LigneID), '')) AS LAN, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'NET' And ALA2.LigneID = LI.LigneID), '')) AS NET, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'PCM' And ALA2.LigneID = LI.LigneID), '')) AS PCM, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'RDM' And ALA2.LigneID = LI.LigneID), '')) AS RDM, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'AMS' And ALA2.LigneID = LI.LigneID), '')) AS AMS, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'MPSR' And ALA2.LigneID = LI.LigneID), '')) AS MPSR, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'MPREJ' And ALA2.LigneID = LI.LigneID), '')) AS MPREJ, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'MPREN' And ALA2.LigneID = LI.LigneID), '')) AS MPREN, (Select ifNull((Select ALA2.QuantiteArticle From Asso_Ligne_Article ALA2 Join Article AR2 On ALA2.ArticleID = AR2.ArticleID Where AR2.CodeArticle = 'PCX' And ALA2.LigneID = LI.LigneID), '')) AS PCX from code_ot ot Join Asso_OT_ND AON On OT.Code_CodeOT = AON.Code_CodeOT Join Ligne LI On AON.LigneID = LI.LigneID Left Join Adresse AD On LI.EquipementID = AD.EquipementID Left Join Asso_Ligne_Resultat_Intervention ALRI On LI.LigneID = ALRI.LigneID Left Join Resultat_Intervention RI On ALRI.ResultatInterventionID = RI.ResultatInterventionID Left Join Essai_Robot ER On ALRI.EssaiRobotID = ER.EssaiRobotID left Join OT_EQP_Planning OEP On OT.Code_CodeOT = OEP.Code_CodeOT left Join Equipe EQ On OEP.CodeEquipe = EQ.CodeEquipe left join DivProd DivProd on (divprod.codedivisionproduction=EQ.codedivisionproduction) join etat_OT on (ot.etatotid=etat_ot.etatotid) where Date(OT.DateHeureContractuelle) >= '"+DateDEB+"' And Date(OT.DateHeureContractuelle) <= '"+DateFIN+"' ";

//System.out.println("ETAT = "+ etat);

if (societe !null || societe ""){
query = query + "And "+societe;
System.out.println("query + societe = "+query);
}else{
query = query;
System.out.println("else societe null or '' "+query);
}
if (ui !null || ui ""){
query = query + "And "+ui;
System.out.println("query + ui = "+query);
}else{
query = query;
System.out.println("else ui null or '' "+query);
}
if (etat !null || etat ""){
query = query + "And "+etat;
System.out.println("query + etat = "+query);
}else{
query = query;
System.out.println("else etat null or '' "+query);
}
if (gtr !null || gtr ""){
query = query + "And "+gtr;
System.out.println("query + gtr = "+query);
}else{
query = query;
System.out.println("else gtr null or '' "+query);
}

//on termine par enquery
query = query + endquery;

//operateur ternaire: if else simplifie
//(condition) ? instruction si vrai : instruction si faux


//query = query+ if(societe != "") societe + if(ui != "") ui + if(etat != "") etat + if(gtr != "") gtr+endquery;
//query = query+societe+endquery;
System.out.println("NEW Query= "+query);
//System.out.println("Query= "+query);

//Execute the Query
rs = stmt.executeQuery(query);
//Fill table with resultset (my own method)
SetTable(rs);

//Will be executed whatever happens
} finally {

/* Release the resources */
if (rs != null) {
try {
rs.close();
} catch (SQLException sqlEx) {
System.out.println("SQLException: " + sqlEx.getMessage());
}//end try
rs = null;
}//end if rs
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlEx) {
System.out.println("SQLException: " + sqlEx.getMessage());
}//end try
stmt = null;
}//end if stmt
if (connexion != null) {
try {
connexion.close();
} catch (SQLException sqlEx) {
// Ignore
}//end try
connexion = null;
}//end if connexion
out.close();
}//end finally
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
// }

} catch (Exception ex) {
System.out.println("Exception: " + ex.getMessage());
}

//END TEST REQUETE
//System.out.println("Now should be CONNECTED");
}//end connectDB


public void showDialog2(){
OKexport = new JButton("EXPORT");
OKexport.addActionListener( n
Afficher la suite 

Votre réponse

3 réponses

Meilleure réponse
uhrand 493 Messages postés samedi 20 mai 2006Date d'inscription 15 juillet 2012 Dernière intervention - 19 août 2009 à 18:44
3
Merci
System.out.println("in BACK");
/****TEST SI DEJA LANCE QUERY*****/
MonModel = (DefaultTableModel) tb.getModel();
if (query != null || !query.equals("")) {
    query = "";
    clear();
} else {
    System.out.println("HERE ELSE QUERY == ??? >>>" + query);
}//end if
d2.setVisible(false);
d1.setVisible(true);

Merci uhrand 3

Avec quelques mots c'est encore mieux Ajouter un commentaire

Codes Sources a aidé 85 internautes ce mois-ci

Commenter la réponse de uhrand
tomski 48 Messages postés mercredi 24 mars 2004Date d'inscription 24 décembre 2009 Dernière intervention - 14 août 2009 à 11:33
0
Merci
re bonjour,


en fait: ma 1ere JDialog oeremt de choisir de selements dans des listes. Ces elements aident a ecrire la requete SQL (MYSQL).
quand on cloik sur OK, ca envoit le resultat de la requete dans une autre Jdialog avec une JTable. La Jtable se remplit bien.

Mais kan je fais "go back" pour revenir a ma premiere JDialog et modifier les elements ke je selectionne dans mes liste s(donc modifier ma requete), alors ma Jtable contient a la fois les resultats de la 1ere requete et ceux de la 2eme requete.


Jaimerais biensur ke ca ne contienne ke le resultat de la derniere requete.

Merci pour votre aide

(_.:~:._)
Commenter la réponse de tomski
tomski 48 Messages postés mercredi 24 mars 2004Date d'inscription 24 décembre 2009 Dernière intervention - 20 août 2009 à 09:16
0
Merci
merci uhrand! works fine!


(_.:~:._)
Commenter la réponse de tomski

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.