-4

I want to insert list of string into Database so usual we will store string directly to database by either using prepared statement or batch statement like that but now I want to insert list of string into database so I have used prepared statement

List<String> Account_Number = Files.lines(Paths.get("D:\\PDFTOEXCEL\\Extractionfrompdf.txt"))
    .filter(s -> s.contains(arra.get(7)))
    .map(s -> s.split(":")[1].trim())
    .collect(Collectors.toList());
System.out.println(Account_Number);

try {
    Connection conn = PDFTOEXCEL.getConnection();
    PreparedStatement stmt = conn.prepareStatement("insert into client_info values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    stmt.setString(1, Account_Number.get(1));
    int k = stmt.executeUpdate();

I have about 31 columns in my database just for showing I have posted only one in this code all are in the list of string only

So now I am getting error in :

while (query_set.next()) {
    row_counter = row_counter + 1;
    **Account_Number = query_set.getString("Account_Number");**

Output:

Error:incompatible types: String cannot be converted to List

The bold one is the error statement

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Joo
  • 1
  • 1
  • just curious, are you in the same class as the poster of [this question](https://stackoverflow.com/questions/54741312/how-to-use-lamba-expression-without-using-final) or are you the same person? – Kartik Feb 19 '19 at 01:43
  • no we are two different person working in same project – Joo Feb 19 '19 at 01:46
  • 1
    Possible duplicate of [Variable used in lambda expression should be final or effectively final](https://stackoverflow.com/questions/34865383/variable-used-in-lambda-expression-should-be-final-or-effectively-final) – Robert Feb 19 '19 at 01:51
  • What is your question? You've only told us what you want to do, but I see no question. Please read the [ask] guide and [edit] the question to provide enough information (and code) to help you. – Zephyr Feb 19 '19 at 02:30

1 Answers1

0

The problem is that Account_Number is of type List, and you try to assign a String to it. That is not possible: a String is not a List. Assuming you want to add this string to the list, you need to use Account_Number.add(...):

Account_Number.add(query_set.getString("Account_Number"));

Given you haven't provided a lot of context, it is hard to say if this is actually the right thing to do.

On a separate note, please try to follow common Java naming conventions. Variables and fields should start with a lowercase letter, and usually underscores are avoided, except in constants. So it should be accountNumber, not Account_Number. Following the conventions will make it easier for people to read your code.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197