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
|
package sentalents.db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Vector;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import sentalents.apps.CVtheque;
public class ResultsSearch {
public ResultsSearch(String a, Object b, Object c, Object d, Object e, JTable t, Vector<String> columnNames, Vector<Vector<Object>> data ) {
Connection conn = ConnectionManager.getInstance().getConnection();
//String sql = "SELECT nom, prenom, niveau, localisation, pays, secteur1, secteur2, secteur3, photo, cv1, cv2, cv3, langue_cv1, langue_cv2, langue_cv3 FROM infos WHERE (niveau ='"+b+"' AND localisation = '"+c+"' AND pays = '"+d+"' AND secteur1 = '"+e+"') OR CONCAT_WS(' ',titre_cv1, titre_cv2, titre_cv3) LIKE '%"+a+"%'";
String sql = "SELECT nom, prenom, niveau, localisation, pays FROM infos WHERE (niveau ='"+b+"' AND localisation = '"+c+"' AND pays = '"+d+"' AND secteur1 = '"+e+"') OR CONCAT_WS(' ',titre_cv1, titre_cv2, titre_cv3) LIKE '%"+a+"%'";
//String sql = "SELECT nom, prenom, niveau, localisation, pays FROM infos WHERE (niveau =? AND localisation = ? AND pays = ? AND secteur1 = ?) OR CONCAT_WS(' ',titre_cv1, titre_cv2, titre_cv3) LIKE '%?%'";
try {
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount();
for (int i = 1; i <= columns; i++) {
columnNames.addElement(metaData.getColumnName(i));
while (rs.next()) {
Vector<Object> row = new Vector<Object>(columns);
for (int j = 1; j <= columns; j++) {
row.addElement(rs.getObject(j));
}
data.addElement(row);
System.out.println(row);
}
}
} catch (Exception e1) {
System.err.println(e1);
}
DefaultTableModel model = new DefaultTableModel(data, columnNames);
t.setModel(model);
ConnectionManager.getInstance().close();
}
} |
Partager