'SQL Exception cannot issue statements that do not produce result sets- Java

public static void main(String[] args) throws Exception{
    
    Connection con = DriverManager.getConnection(url, uname, pass);
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery(query);
    
    String name = rs.getString("NAME");
    
    System.out.println(name);
    
    st.close();
    con.close();
}

: When I run this code this is the error i am getting..

Exception in thread "main" java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result sets.

What can I do to fix this error?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source