gpt4 book ai didi

java - 陷入困境,无法从数据库中存储为列表的数据中替换停用词(txt.file)

转载 作者:行者123 更新时间:2023-12-02 12:26:16 24 4
gpt4 key购买 nike

请查看使用replace方法的for循环部分的代码我无法替换从数据库获取的数据中的停用词。错误显示,数组绑定(bind)异常:1。

请查看使用replace方法的for循环部分的代码我无法替换从数据库获取的数据中的停用词。错误显示,数组绑定(bind)异常:1。请查看使用替换方法的 for 循环部分的代码我无法替换从数据库获取的数据中的停用词。错误显示,数组绑定(bind)异常:1。

我愿意解决这个问题,给我一些建议

package chatbot;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class keywords{

private static Scanner scan2;
private static final String driverName = "oracle.jdbc.driver.OracleDriver";
private static final String QUER = null;
//private static final String SCOR = null;
// private static final String SCORE =
private static final String ANSW = null;


public static void main(String[] args) throws IOException, SQLException {

Connection con = null;
Statement stmnt = null;
ResultSet result = null;

Set<String> list1= new HashSet<>();
try {
Class.forName(driverName);
con = DriverManager.getConnection("jdbc:oracle:thin:@10.144.97.144:1521:NQLDEV", "DEVNQL", "DEVNQL");
stmnt = con.createStatement();
System.out.println("Connection established");

List<String> rsl1 = new ArrayList<>();

List<String> rsl3 = new ArrayList<>();

String query = "SELECT * FROM DEVNQL.CHATKEY";

ResultSet rs = stmnt.executeQuery(query);


while (rs.next()) {
rsl1.add(rs.getString(1));
rsl3.add(rs.getString(3));
}
//System.out.println("result "+rsl1 + " "+rsl3);


File file = new File("M:\\Documents\\stop-word-list.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String st;
while((st=br.readLine()) != null){

ArrayList<String> wordList = new ArrayList<String>(Arrays.asList(st));
//List<String> ux = new ArrayList<>(Arrays.asList(st));


for(int i=0;i<rsl1.size()-1;i++){

for(String n:wordList)

if(rsl1.contains(n.getBytes()[i])){
rsl1.get(i).replace(n.charAt(i)+"\\rsl1+", "");
//note this will remove spaces at the end
}
}
System.out.println(rsl1);
}}



// for (int i=0;i<=rsl1.size()-1;i++){





/*
for (String removeword:wordList){

System.out.println("removeword "+removeword+ " "+rsl1.get(i)+
" "+rsl1.get(i).contains(removeword));
rsl1.get(i).replace("hi","abcd********");
if (rsl1.get(i).contains(removeword)) {

rsl1.get(i).replace("hi","abcd********");
} // end if
} // end for
*/ // } // end for

// System.out.println("result "+rsl1);
// }
// System.out.println("replace "+rsl1.get(0).replace("hi", "abcde"));

// }



catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}

fi`enter code here`nally {
if (stmnt != null) {
stmnt.close();
}

if (con != null) {
con.close();
}
}
}}

最佳答案

replace 实际上返回一个新的字符串,就像 Java 中的字符串是不可变的

所以

String newString =  rsl1.get(i).replace(n.charAt(i)+"\\rsl1+", "");

关于java - 陷入困境,无法从数据库中存储为列表的数据中替换停用词(txt.file),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45476103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com