我有一个名为“句子”的类ArrayList。每个句子包含值“单词”。我必须检查进入MySQL数据库的每个单词是否是停用词。假设我有200个“句子”,每个句子都有不同数量的“单词”。
我已经将“单词”一个接一个地检查到数据库中,当它达到2500个“单词”数量时(有时直到连接失败之前,它一直命中直到第3500个单词),它变成了错误。但是,如果“单词”的数量低于2500,就可以了。
这是我的查询代码
public Query() throws SQLException, ClassNotFoundException{
try{
cd = new Connect();
connect = cd.getConnection();
statement = (Statement) connect.createStatement();
}catch(SQLException e){
System.err.println("Database connecting failed");
}
}
public boolean isStopWords(String word) throws SQLException{
String query = "SELECT stopwords FROM stopword WHERE stopwords = '"+word+"'";
rs = statement.executeQuery(query);
if(!rs.next()) return false;
else return true;
}
这是我的连接代码
public Connect() throws SQLException{
try{
Class forName = Class.forName ("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException ex){
}
connect = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/mydatabase", "root", null);
}
public Connection getConnection(){
return connect;
}
这是我从Sentence类中检索Word的方法。String [] tempWords是一个对象Sentence中Word的值。句子本身将根据ArrayList句子的大小循环播放
protected ArrayList<String> eraseStopWord (String[] tempWords) throws SQLException, ClassNotFoundException{
result = new ArrayList<String>();
db = new Query();
for(int i=0;i<tempWords.length;i++){
if(!db.isStopWords(tempWords[i])){
result.add(tempWords[i]);
}
}
return result;
}
为什么直到被击中大约2500个“单词”才好呢?(有时直到连接失败之前第3500个字都可以,但在第2500个字以下才稳定)
更新:现在我知道连接在哪里停止。它在第153个句子循环处停止。所以它不依赖于文字。仍然照顾错误
我的错。在我之前的代码中,每次创建句子时我都会建立连接(db = new Query)
protected ArrayList<String> eraseStopWord (String[] tempWords) throws SQLException, ClassNotFoundException{
result = new ArrayList<String>();
db = new Query();
for(int i=0;i<tempWords.length;i++){
if(!db.isStopWords(tempWords[i])){
result.add(tempWords[i]);
}
}
return result;
}
因此,当到达第153个句子时,它将由于连接过多而停止。解决方法是在Sentence循环之前编写打开的连接代码
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句