ResultSet error "Can not find symbol"

0

I recently worked with a code that connects to a database in mysql. Its functionality is to insert data to the previously created table and then with a button to give functionality to empty TxtField in Jframe to refill.

The error is shown to me only in the ResultSet with the option to create class and it is also worth mentioning that I have created the Statement previously.

I appreciate help. GREETINGS!

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    Connection conectar = null;
        try{
            Class.forName("com.mysql.jdbc.Driver");

            conectar = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/name","root","");
        }catch (ClassNotFoundException ex) {
            Logger.getLogger(datos.class.getName()).log(Level.SEVERE, null, ex);
        }catch (SQLException ex) {
            Logger.getLogger(datos.class.getName()).log(Level.SEVERE, null, ex);
        }
        String idContribuyente=this.jTextField4.getText();
        try{
            Statement s=(Statement) conectar.createStatement();
            ResultSet rs=s.executeQuery("query");
    
asked by Suri Gang's Hallen 15.05.2018 в 08:17
source

2 answers

0

The sentence

ResultSet rs=s.executeQuery("query");

It will not work, "query" is not valid SQL, that string should be something like "select <columnas> from..."

    
answered by 15.05.2018 в 09:31
0

The executeQuery method returns a ResultSet object defined by the query you define as a parameter:

 //ResultSet rs = s.executeQuery("query");
 ResultSet rs = stmt.executeQuery(query);

Therefore query must be a variable that contains your query, for example:

 String query = "select * from basededatos.tabla";
 ...
 ...
 ResultSet rs = stmt.executeQuery(query);

Review the example of the documentation .

    
answered by 15.05.2018 в 19:00