-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBconnect.java
86 lines (79 loc) · 2.51 KB
/
DBconnect.java
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
package edu.uci.ics.crawler4j.examples.basic;
import java.sql.*;
public class DBconnect {
private Connection con;
private Statement statement;
private ResultSet rs;
public DBconnect()
{
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/webcrawl","root","");
statement = con.createStatement();
}catch(Exception e)
{
System.out.println("Error : " + e);
}
}
public void putData(String url, String anchor, String html)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/webcrawl","root","");
String query = "INSERT INTO `webcrawl`.`l3s` (`URL`, `AnchorText`, `HTML`) VALUES (?, ?, ?)";
PreparedStatement preparedStmt = con.prepareStatement(query);
preparedStmt.setString (1, url);
preparedStmt.setString (2, anchor.toString());
preparedStmt.setString (3, html);
preparedStmt.execute();
}catch(Exception e)
{
System.out.println("Error : "+ e);
}
}
public void getData()
{
try
{
String query = "Select * from l3s";
rs = statement.executeQuery(query);
System.out.println("Records List : ");
while(rs.next())
{
String urldb = rs.getString("URL");
String htmldb = rs.getString("HTML");
String AnchorText = rs.getString("AnchorText");
System.out.println("\nURL : " + urldb + " " + "\nHTML : " + htmldb + " " + "\nAnchor Text : " + AnchorText );
}
}catch(Exception e)
{
System.out.println("Error : "+ e);
}
}
public void searchData(String Search)
{
try
{
/*Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/webcrawl","root","");
String query = "Select * from l3s where AnchorText like '%?%'";
PreparedStatement preparedStmt = con.prepareStatement(query);
preparedStmt.setString (1, Search);
preparedStmt.execute();*/
String query = "Select * from l3s where AnchorText like '%" + Search + "%'";
rs = statement.executeQuery(query);
System.out.println("Records List : ");
while(rs.next())
{
String urldb = rs.getString("URL");
String htmldb = rs.getString("HTML");
String AnchorText = rs.getString("AnchorText");
System.out.println("\nURL : " + urldb + " " + "\nHTML : " + htmldb + " " + "\nAnchor Text : " + AnchorText );
}
}catch(Exception e)
{
System.out.println("Error : "+ e);
}
}
}