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
| @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...");
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery("select * from videos where nomVideo='"+KeyWord+"'");
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
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);
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.
}
return table;
} |
Partager