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
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package packageIden;
import com.mysql.jdbc.ResultSetMetaData;
import java.awt.Dimension;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import packageIden.ListedeRecherche.ImageRenderer;
/**
*
* @author darina
*/
@WebService()
public class Iden {
/**
* Web service operation
*/
@WebMethod(operationName = "IdenOperation")
public String IdenOperation(@WebParam(name = "login")
String login, @WebParam(name = "pass")
String pass) {
//TODO write your implementation code here:
String nnoomm = null;
try {
String username = "root";
String password = "0000";
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = new String("jdbc:mysql://localhost:3306/iptv");
Connection conn = DriverManager.getConnection(url, username, password);
System.out.println("OK connexion réussie...");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from clients");
// String l=jTextField1.getText();
// String m=jPasswordField2.getText();
while (rs.next())
{
String l1 = rs.getString("login");
String m1 = rs.getString("password");
if ((l1.equals(login))&& (m1.equals(pass)))
{ String nom = rs.getString("nom");
System.out.println(nom + "\n");
nnoomm=nom;
// Menu m= new Menu();// question ici ? : es-ce que c'est illogique d'envoyer un jframe dans un web service
// m.setVisible(true);
// a.setSize(new Dimension (800,500));
}
/*else { JOptionPane.showMessageDialog(null, "Valeur incorrecte de nom dutilisateur ou/et de mot de passe. " , "Erreur",
JOptionPane.ERROR_MESSAGE);
}*/
}
// System.out.println("Valeur de nnoomm : "+nnoomm);
//nnoomm=rs.getString("nom");
rs.close();
stmt.close();
conn.close();
System.out.println("Déconnexion réussie...");
} catch (SQLException ex) {
System.out.println("exception"+ex.toString());
} catch (InstantiationException ex) {
System.out.println("exception"+ex.toString());
} catch (IllegalAccessException ex) {
System.out.println("exception"+ex.toString());
} catch (ClassNotFoundException ex) {
System.out.println("exception"+ex.toString());
}
return ("Welcome " +nnoomm);
}
/**
* Web service operation
*/
@WebMethod(operationName = "SearchOperation")
public JTable SearchOperation(@WebParam(name = "KeyWord")
String KeyWord) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
String[] columnNames = {"Videos","Information"};
JTable table = null;
//---------Cconnexion à la base de données:----------------------
String username = "root";
String password = "0000";
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/mabase";
Connection conn = (Connection) DriverManager.getConnection(url, username, password);
System.out.println("OK connexion réussie...");
String Vid ="forgiveMe";// jTextField1.getText();---!!! à modifier
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery("select * from videos where nomVideo='"+Vid+"'");//---!!!ou description à ajouter ultérieurement
String name=rs.getString("nomVideo");
ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData();
rs.last();
int NbreResultats=rs.getRow();
System.out.println("Le nombre des résultats vaut "+NbreResultats);// to del
//int columns = md.getColumnCount();// not for use now
Object[][] data = new Object[NbreResultats][columnNames.length];
rs.beforeFirst();
String NEWLINE = System.getProperty("line.separator");
while (rs.next()) {
String inf="";
inf=inf+" Nom de la vidèo :"+rs.getString("nomVideo")+NEWLINE+
" Catégorie :"+rs.getString("categorie")+NEWLINE+
" Durée :"+rs.getString("duree")+NEWLINE;
String Ligne1=" Nom de la vidèo :"+rs.getString("nomVideo");
String Ligne2=" Catégorie :"+rs.getString("categorie");
String Ligne3=" Durée :"+rs.getString("duree");
String im=rs.getString("lien");
System.out.println(im);// to del
JLabel label =new JLabel("<html>"+Ligne1+"<br>"+Ligne2+"<br>"+Ligne3+"</html>");
System.out.println(inf);
//ImageIcon ic= new ImageIcon("chemin de l image");
data[0][0]=null;
data[0][1]=label.getText();
System.out.println(data[0][1].toString());
rs.close();
stmt.close();
table = new JTable(data, columnNames);//enlever final
table.setPreferredScrollableViewportSize(new Dimension(958, 581));
table.setFillsViewportHeight(true);
//table.setDefaultRenderer(null, this);
ImageIcon iconv = new ImageIcon(im);
// table.getColumnModel().getColumn(0).setCellRenderer((TableCellRenderer) new ImageRenderer());//importanteeeeee
table.setRowHeight(300);
JScrollPane scrollPane = new JScrollPane(table);//Create the scroll pane and add the table to it.
table.add(scrollPane);//Add the scroll pane to this panel.
}
/**
* Web service operation
*/
return table;
}
} |
Partager