📄 crawler.java
字号:
}
else if(count >= 4)
{
con4=DriverManager.getConnection(connectionAddress4,"","");
stmt=con4.createStatement();
stmt.executeUpdate(insertString);
stmt.close();
con4.close();
}
}
catch(SQLException ex)
{
System.err.println("SQLException2: "+ex.getMessage());
}
}
public void delete(String urlAddress)
{
String deleteString;
deleteString="delete from CRAWLTABLE where URLADDRESS='"+urlAddress+"'";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
if(count == 1)
{
con1=DriverManager.getConnection(connectionAddress1,"", "");
stmt=con1.createStatement();
stmt.executeUpdate(deleteString);
stmt.close();
con1.close();
}
if(count == 2)
{
con2=DriverManager.getConnection(connectionAddress2,"", "");
stmt=con2.createStatement();
stmt.executeUpdate(deleteString);
stmt.close();
con2.close();
}
if(count == 3)
{
con3=DriverManager.getConnection(connectionAddress3,"", "");
stmt=con3.createStatement();
stmt.executeUpdate(deleteString);
stmt.close();
con3.close();
}
if(count >= 4)
{
con4=DriverManager.getConnection(connectionAddress4,"", "");
stmt=con4.createStatement();
stmt.executeUpdate(deleteString);
stmt.close();
con4.close();
}
}
catch(SQLException ex)
{
System.err.println("SQLException2: "+ex.getMessage());
}
}
public boolean isRecordFalse()
{
boolean flag=false;
String query;
query=" select URLADDRESS from CRAWLTABLE "+
"where ISCRAWLED='f'";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
if(count == 1)
{
con1=DriverManager.getConnection(connectionAddress1,"", "");
stmt=con1.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
flag= true;
//System.out.println(flag);
}
else
{
flag= false;
}
stmt.close();
con1.close();
}
if(count == 2)
{
con2=DriverManager.getConnection(connectionAddress2,"", "");
stmt=con2.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
flag= true;
//System.out.println(flag);
}
else
{
flag= false;
}
stmt.close();
con2.close();
}
if(count == 3)
{
con3=DriverManager.getConnection(connectionAddress3,"", "");
stmt=con3.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
flag= true;
//System.out.println(flag);
}
else
{
flag= false;
}
stmt.close();
con3.close();
}
if(count >= 4)
{
con4=DriverManager.getConnection(connectionAddress4,"", "");
stmt=con4.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
flag= true;
//System.out.println(flag);
}
else
{
flag= false;
}
stmt.close();
con4.close();
}
}
catch(SQLException ex)
{
System.err.println( "SQLException3: "+ex.getMessage());
}
return flag;
}
public String retrieveFirst()
{
String query,s="";
query=" select URLADDRESS from CRAWLTABLE where "+
"ISCRAWLED='f' order by SERIAL";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
return null;
}
try
{
if(count == 1)
{
con1=DriverManager.getConnection(connectionAddress1,"", "");
stmt=con1.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
s=rs.getString("URLADDRESS");
}
stmt.close();
con1.close();
}
if(count == 2)
{
con2=DriverManager.getConnection(connectionAddress2,"", "");
stmt=con2.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
s=rs.getString("URLADDRESS");
}
stmt.close();
con2.close();
}
if(count == 3)
{
con3=DriverManager.getConnection(connectionAddress3,"", "");
stmt=con3.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
s=rs.getString("URLADDRESS");
}
stmt.close();
con3.close();
}
if(count >= 4)
{
con4=DriverManager.getConnection(connectionAddress4,"", "");
stmt=con4.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
s=rs.getString("URLADDRESS");
}
stmt.close();
con4.close();
}
}
catch(SQLException ex)
{
System.err.println( "SQLException3: "+ex.getMessage());
return null;
}
return s;
}
public boolean contains(String strURL)
{
boolean flag=false;
String query;
query=" select URLADDRESS from CRAWLTABLE "+
"where URLADDRESS='"+strURL+"'";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
if(count == 1)
{
con1=DriverManager.getConnection(connectionAddress1,"", "");
stmt=con1.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
flag= true;
//System.out.println(flag);
}
else
{
flag= false;
//System.out.println(flag);
}
stmt.close();
con1.close();
}
if(count == 2)
{
con2=DriverManager.getConnection(connectionAddress2,"", "");
stmt=con2.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
flag= true;
//System.out.println(flag);
}
else
{
flag= false;
//System.out.println(flag);
}
stmt.close();
con2.close();
}
if(count == 3)
{
con3=DriverManager.getConnection(connectionAddress3,"", "");
stmt=con3.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
flag= true;
//System.out.println(flag);
}
else
{
flag= false;
//System.out.println(flag);
}
stmt.close();
con3.close();
}
if(count >=4)
{
con4=DriverManager.getConnection(connectionAddress4,"", "");
stmt=con4.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
{
flag= true;
//System.out.println(flag);
}
else
{
flag= false;
//System.out.println(flag);
}
stmt.close();
con4.close();
}
}
catch(SQLException ex)
{
System.err.println( "SQLException3: "+ex.getMessage());
}
return flag;
}
public void updateRecord(String urlAddress)
{
String updateString;
updateString="update CRAWLTABLE"+
" set ISCRAWLED='t'" + " where URLADDRESS='"+urlAddress+"'";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
if(count == 1)
{
con1=DriverManager.getConnection(connectionAddress1,"", "");
stmt=con1.createStatement();
stmt.executeUpdate(updateString);
stmt.close();
con1.close();
}
if(count == 2)
{
con2=DriverManager.getConnection(connectionAddress2,"", "");
stmt=con2.createStatement();
stmt.executeUpdate(updateString);
stmt.close();
con2.close();
}
if(count == 3)
{
con3=DriverManager.getConnection(connectionAddress3,"", "");
stmt=con3.createStatement();
stmt.executeUpdate(updateString);
stmt.close();
con3.close();
}
if(count >= 4)
{
con4=DriverManager.getConnection(connectionAddress4,"", "");
stmt=con4.createStatement();
stmt.executeUpdate(updateString);
stmt.close();
con4.close();
}
}
catch(SQLException ex)
{
System.err.println("SQLException4: "+ex.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -