0
奇怪的是,我在Eclipse Luna中有一個Java應用程序,當調試它時,我試圖使用F6它不會「超越」,而是「步入」。Eclipse Luna F6不會跨越
奇怪的是,我在Eclipse Luna中有一個Java應用程序,當調試它時,我試圖使用F6它不會「超越」,而是「步入」。Eclipse Luna F6不會跨越
我正試圖在Eclipse Luna中構建Java應用程序。這是一個來自 here的數據庫應用程序。
隨着兩個源文件(DB.java):
`import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DB {
public Connection conn = null;
public DB() {
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/Crawler";
conn = DriverManager.getConnection(url, "root", "admin213");
System.out.println("conn built");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public ResultSet runSql(String sql) throws SQLException {
Statement sta = conn.createStatement();
return sta.executeQuery(sql);
}
public boolean runSql2(String sql) throws SQLException {
Statement sta = conn.createStatement();
return sta.execute(sql);
}
@Override
protected void finalize() throws Throwable {
if (conn != null || !conn.isClosed()) {
conn.close();
}
}
}`
和Main.java:
`import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Main {
public static DB db = new DB();
public static void main(String[] args) throws SQLException, IOException {
db.runSql2("TRUNCATE Record;");
processPage("http://www.mit.edu");
}
public static void processPage(String URL) throws SQLException, IOException{
//check if the given URL is already in database
String sql = "select * from Record where URL = '"+URL+"'";
ResultSet rs = db.runSql(sql);
if(rs.next()){
}else{
//store the URL to database to avoid parsing again
sql = "INSERT INTO `Crawler`.`Record` " + "(`URL`) VALUES " + "(?);";
PreparedStatement stmt = db.conn.prepareStatement(sql,
Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, URL);
stmt.execute();
//get useful information
Document doc = Jsoup.connect("http://www.mit.edu/").get();
if(doc.text().contains("research")){
System.out.println(URL);
}
//get all links and recursively call the processPage method
Elements questions = doc.select("a[href]");
for(Element link: questions){
if(link.attr("href").contains("mit.edu"))
processPage(link.attr("abs:href"));
}
}
}
}`
忘了包括MySQL的連接器的Java-5.1.16槽。 jar進入構建路徑。 這會導致DB() 初始化程序代碼中發生初始化時發生異常。至少這是我的假設,Eclipse的行爲是 惱火(也許它是一個功能?),並且這一步沒有正常工作。
這個問題似乎是脫離主題,因爲它缺乏任何細節使其可以回答。 – 2014-10-31 09:47:43
你是否仔細檢查了你的鑰匙扣? – GGrec 2014-10-31 10:06:30