How do I call a method within a setString

jason-hernandez-73

I am trying to use a setString to call a method from another class, but I get an error message that says that cannot be resolved to a variable.

In my Tag class, I have:

import java.util.List;
import models.Book;


public class Tag {

    private String isbn_13;
    private String tag_name;
    
    public Tag(String isbn, String tagName) {
        this.isbn_13 = isbn;
        this.tag_name = tagName;
    }
    
    public Tag() {
        this.isbn_13 = null;
        this.tag_name = null;
    }
    
    public String getIsbn13() {
        return isbn_13;
    }

    public void setIsbn13(String isbn) {
        this.isbn_13 = isbn;
    }
    
    public String getTag() {
        return tag_name;
    }
    
    public void setTag(String tagName) {
        this.tag_name = tagName;
    }
    
    public void add(List<Tag> book_tags) {
        // TODO Auto-generated method stub
        
    }

}

Now, in my TagImpl class, the relevant method is

public boolean addTag(Tag tag) {
        try {
            connection = DAOUtilities.getConnection();
            String sql = "INSERT INTO Book_tags VALUES (?, ?)"; 
            stmt = connection.prepareStatement(sql);
            
            stmt.setString(1, tag.setIsbn13(isbn)); // Error here "isbn cannot be resolved to a variable"
            stmt.setString(2, tag.setTag(tagName)); // Error here "tagName cannot be resolved 
                                                    // to a variable"
            
            if (stmt.executeUpdate() != 0)
                return true;
            else
                return false;
            
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        } finally {
            closeResources();
        }
    }

I have looked at all the documentation I can think of, and the tutorials I can find, and all of them look like this is correct. The only difference is that some of them show empty parentheses, i.e. stmt.setString(1, tag.setIsbn13()); but that just gives a different error, "The method setIsbn13(String) in the type Tag is not applicable for the arguments ()" Also, it makes no difference if I change (isbn) to (isbn_13) or (tagName) to (tag_name) -- it still "cannot be resolved to a variable.

Arvind Kumar Avinash

You have to get the isbn_13 and tag_name from tag and set into stmt.

Replace

stmt.setString(1, tag.setIsbn13(isbn)); 
stmt.setString(2, tag.setTag(tagName));

with

stmt.setString(1, tag.getIsbn13()); 
stmt.setString(2, tag.getTag());

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I call a static method within a nested class?

How do I call a fromRootViewController method within a UIView class?

How do I call a base class method from within the same overloaded derived class method in python?

How do i call a method within another method in react class Es6

How do I call methods within a constructor?

How do you call a object method from within an addEventListener() call?

How do I call a method on my ServiceWorker from within my page?

How can I call a block within the execute method of a ScheduledTask?

How do I call a variable in another method

How do i call this method for debugging?

How do I call a method when exiting?

How do I call an object as method parameter?

How do I call a method by string variable?

How do I call upon the method in this program?

How do I 'reset' a method on call?

How do I get the method name from within that method?

ASP.NET MVC - How do I Call a Controller Method from within a View to Redirect to Multiple Other Views?

How do I call a function from within a statement in the event listener?

Spring Webflux - How do I call an reactive endpoint within a WebFilter

how do i call web service from within a web service

How do I call a function within ajax using codeigniter to update

How do I call a function within the same class in JavaScript?

How do I call a function within an IIFE expression

How do I call a function from within a nested function in typescript?

How do I call my function from within my function?

How do I call CreateMenu() from within an Apps Script Library?

How do I update an api call within a while loop?

How do I call firebase functions from within a react component

How do I call a different REST API within a express route?