Error setting Executesql method

Asked

Viewed 116 times

1

When creating the execute method it generates error at this point rs = stm.executeQuery(sql) what can I do

public void excutaSQL(String sql){
        try {
            stm=(Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

            rs = stm.executeQuery(sql);// o erro está neste linha 
        } catch (SQLException ex) {
            Logger.getLogger(Conection.class.getName()).log(Level.SEVERE, null, ex);
        }

     }

error: cannot find Symbol
rs = stm.executeQuery(sql);
Symbol: method executeQuery(String)
Location: variable stm of type Statement
1 error

import java.beans.Statement;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
  • 1

    Where is the value of your variable SQL

  • 1

    What is the error?

  • You’re probably importing the library Statement of java.beans instead of java.sql. Puts the import to check in

1 answer

5


You are importing the class Statement wrong. Change the import class Statement to the following:

import java.sql.Statement;

Or just remove the line below, after all you are already doing the import for all classes (with import java.sql.*):

import java.beans.Statement;

Class documentation java.sql.Statement

Browser other questions tagged

You are not signed in. Login or sign up in order to post.