Hi, im trying to query an oracle db set up of table is all done and filling it is fine but when i try to send a query to the db using a resultset to store the outcome im getting the error "cannot convert int to ResultSet" ive looked at all the examples of resultset i can find on the web and they all seem to use the exact same syntax as me so i cant see the error. here is the code

import java.sql.*;
import java.io.*;

public class test {
    public static void main (String[] args){
        BufferedReader input = new BufferedReader(
                new InputStreamReader( System.in));
        
        String command = null;
        System.out.println("Enter SQL Query: ");
        try {
            command = input.readLine();
        }
        catch(Exception e) {
            System.out.println("Couldn't read from keyboard because"
                + e);

            System.exit(1);
        }
        search(command);
    }
    PreparedStatement pstmt = null;
    
    
    public static void search(String query){
        Connection conn = DBInfo.connectToDatabase();
        Statement stmt =null;
        ResultSet rs =null
        try{
            stmt = conn.createStatement();
        }
        catch(SQLException sqle){
            System.out.print("Unable to create search  because ");
            System.out.println(sqle);
            System.exit(1);
        }
        try {
            rs = stmt.executeUpdate(query);
            
        }
        catch(SQLException sqle){
                System.out.print("Unable to search records because ");
                System.out.println(sqle);
                System.exit(1);
        }
        try {
            conn.close();
        }
        catch(SQLException sqle){}
    }
    
}

crap just realised i actually wasnt doing the same as what the other stes said was just reading their .executeQuery as my .executeUpdate :( doh sorry for the bother people

Hi , executeUpdate doen't return resultset it returns integer.That may be the cause for the exception .verify once .

Hi, im trying to query an oracle db set up of table is all done and filling it is fine but when i try to send a query to the db using a resultset to store the outcome im getting the error "cannot convert int to ResultSet" ive looked at all the examples of resultset i can find on the web and they all seem to use the exact same syntax as me so i cant see the error. here is the code

import java.sql.*;
import java.io.*;
 
public class test {
    public static void main (String[] args){
        BufferedReader input = new BufferedReader(
                new InputStreamReader( System.in));
 
        String command = null;
        System.out.println("Enter SQL Query: ");
        try {
            command = input.readLine();
        }
        catch(Exception e) {
            System.out.println("Couldn't read from keyboard because"
                + e);
 
            System.exit(1);
        }
        search(command);
    }
    PreparedStatement pstmt = null;
 
 
    public static void search(String query){
        Connection conn = DBInfo.connectToDatabase();
        Statement stmt =null;
        ResultSet rs =null
        try{
            stmt = conn.createStatement();
        }
        catch(SQLException sqle){
            System.out.print("Unable to create search  because ");
            System.out.println(sqle);
            System.exit(1);
        }
        try {
            rs = stmt.executeUpdate(query);
 
        }
        catch(SQLException sqle){
                System.out.print("Unable to search records because ");
                System.out.println(sqle);
                System.exit(1);
        }
        try {
            conn.close();
        }
        catch(SQLException sqle){}
    }
 
}
This article has been dead for over six months. Start a new discussion instead.