我解析出HTML文件中的數據並將它們寫入數據庫。 它一直運行到10分鐘前,當運行java工作流程時突然出現越來越多的異常。我已經嘗試過這樣的:set @@global.max_connections = 1250;
以下是錯誤的例子:我是執行我的代碼似乎效率低下,並引發jdbc異常
Jul 21, 2014 4:22:58 PM org.jsoup.examples.Database OpenConnectionDB
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
at sun.reflect.GeneratedConstructorAccessor9.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1023)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1112)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2508)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2541)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2323)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.GeneratedConstructorAccessor5.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.jsoup.examples.Database.OpenConnectionDB(Database.java:34)
at org.jsoup.examples.Database.insert(Database.java:67)
at org.jsoup.examples.parseEasy.getData(parseEasy.java:61)
at org.jsoup.examples.parseEasy.main(parseEasy.java:30)
的(牆)代碼是在這裏。也許你的某個人對我在這裏犯的錯誤有很好的看法。我無法弄清楚,我不希望任何人通過它進行搜索。如果有人立即知道錯誤發生在哪裏,我很樂意聽到它。謝謝!
package org.jsoup.examples;
import java.io.*;
import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.Elements;
import java.io.IOException;
/**
* Example program to list links from a URL.
*/
public class parseEasy {
static parseEasy parseIt = new parseEasy();
String companyName = "Platzhalter";
String jobTitle = "Platzhalter";
String location = "Platzhalter";
String timeAdded = "Platzhalter";
public static void main(String[] args) throws IOException
{
Database connect = new Database();
connect.OpenConnectionDB();
parseIt.getData();
connect.closeConnectionDB();
}
//
public void getData() throws IOException
{
Database c = new Database();
Document document = Jsoup.parse(new File("C:/Talend/workspace/WEBCRAWLER/output/keywords_Medizin.txt"), "utf-8");
Elements elements = document.select(".joblisting");
for (Element element : elements)
{
// Counter for Number of Elements returned
// Parse Data into Elements
Elements jobTitleElement = element.select(".job_title span");
Elements companyNameElement = element.select(".company_name span[itemprop=name]");
Elements locationElement = element.select(".locality span[itemprop=addressLocality]");
Elements dateElement = element.select(".job_date_added [datetime]");
// Strip Data from unnecessary tags
String companyName = companyNameElement.text();
String jobTitle = jobTitleElement.text();
String location = locationElement.text();
String timeAdded = dateElement.attr("datetime");
c.insert(companyName, jobTitle, timeAdded, location);
// Test output
//System.out.println("Firma:\t"+ companyName + "\t" + jobTitle + "\t in:\t" + location + " \t Erstellt am \t" + timeAdded + "\t. Eintrag Nummer:\t" + count);
}
}
}
連接太多。 –
爲什麼你要在'getData()'中創建一個新的數據庫? – vandale
我對編程頗爲陌生。我想我不能從一些靜態的上下文中引用它?嗯,任何想法如何解決它?謝謝你到目前爲止 – ZedBrannigan