
Java HtmlUnit(Mysql)
Publicado por Osvak (1 intervención) el 01/03/2017 19:37:47
Con el Siguiente ejercicio pretendo obtener datos de la web y guardarlos en una base de datos ...EL problema es que no me aguarda ningun datos en la base de datos....Alguien podria ayudarme a corregir el error
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
public class Main {
public static DB db = new DB();
public static void Oscar (String Nombre,String Fecha) throws SQLException, IOException{
String sql = "select * from Datos where Nombre = '"+Nombre+"' AND Fecha ='"+Fecha+"'";
ResultSet rs = db.runSql(sql);
if(rs.next()){
}else{
//store the URL to database to avoid parsing again
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45);
HtmlPage page = webClient.getPage("http://www.despegar.com.mx/turismo/zlo/manzanillo/recomendaciones");
DomNodeList<DomElement> List = page.getElementsByTagName("p");
for (DomElement element : List){
if (element.getAttribute("class").equals("comment-name")){
Nombre = element.getTextContent();
Oscar (Nombre,Fecha);
System.out.println("NOmbre" + Nombre);
}
if (element.getAttribute("class").equals("comment-date")){
Fecha = element.getTextContent();
Oscar (Nombre,Fecha);
System.out.println("Fecha" + Fecha);
}
}
}
}
public static void main(String[] args) throws SQLException, IOException {
db.runSql2("TRUNCATE Datos;");
Oscar ("osva","17 de mayo");
}
}
Valora esta pregunta


0