public static void JD() throws IOException{
File input =new File("/Users/huboqin/Downloads/网页1/京东/jd450.html");
Document doc=Jsoup.parse(input,"GB18030");
Elements ele=doc.getElementsByClass("comment-content");
String user=ele.select("dd").first().text();
try {
Class.forName("com.mysql.jdbc.Driver"); System.out.println("Success loading Mysql Driver!");
} catch (Exception e) {
System.out.print("Error loading Mysql Driver!");
e.printStackTrace(); }
Connection conn =null;
Statement stmt = null;
try{
conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/Test", "root", "");;
stmt =(Statement) conn.createStatement();
}
catch(SQLException e1){
e1.printStackTrace();
}
File file =new File("/Users/huboqin/Documents/数据/京东/450.txt");
FileInputStream fis =null;
try{
fis = new FileInputStream(file);
InputStreamReader input1 =new InputStreamReader(fis);
BufferedReader br=new BufferedReader(input1);
String line=null;
String sql=null;
try{
while((line=br.readLine())!=null){
sql="insert into Details(CommentID,MarketID,ProductID,Comments,Stars)values('"+ 1 +"','"+2+"','"+1+"','"+line+"','"+5+"')";
stmt.executeUpdate(sql);
}
}
catch(IOException e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
}
catch(FileNotFoundException e){
e.printStackTrace();
}
}